2016-01-13 64 views
1

我有一個mysql查詢列表,我試圖在我的瓶子網站返回。這可能嗎?以下是我的:Python返回列表中的瓶子

def create_new_location(): 

    kitchen_locations = select_location() 

    return template(''' 
     % for kitchen_location in {{kitchen_locations}}: 
      <a href="/{{kitchen_location}}/">{{kitchen_location}} Kitchen</a> 
      <br/> 
     % end''',kitchen_locations=kitchen_locations) 

這是我得到的錯誤。

Traceback (most recent call last): 
    File "/usr/local/lib/python2.7/site-packages/bottle.py", line 862, in _handle 
return route.call(**args) 
    File "/usr/local/lib/python2.7/site-packages/bottle.py", line 1732, in wrapper 
rv = callback(*a, **ka) 
    File "index.py", line 32, in create_new_location 
</form>''',kitchen_locations=kitchen_locations) 
    File "/usr/local/lib/python2.7/site-packages/bottle.py", line 3609, in template 
return TEMPLATES[tplid].render(kwargs) 
    File "/usr/local/lib/python2.7/site-packages/bottle.py", line 3399, in render 
self.execute(stdout, env) 
    File "/usr/local/lib/python2.7/site-packages/bottle.py", line 3386, in execute 
eval(self.co, env) 
    File "<string>", line 6, in <module> 
TypeError: unhashable type: 'set' 
+0

沒有這是不可能的 –

+0

什麼是你得到的錯誤? –

+0

我基本上想要顯示一個MySQL查詢,並把每個項目的鏈接。 –

回答

1

得到的(我花了一段時間...)

% for kitchen_location in {{kitchen_locations}}: 

應該

% for kitchen_location in kitchen_locations: 

當使用%的開頭,你不需要{{} }。

此錯誤:

TypeError: unhashable type: 'set' 

正試圖在另一組的一組使用一組文字{{kitchen_locations}} ==>

kitchen_locations。由於設置不哈希能夠得到錯誤

+0

它的工作!謝謝!你能幫我理解套件或列表的可排序性或不可排序性嗎? –

+0

@VongLy - http://stackoverflow.com/questions/2671376/hashable-immutable和http://stackoverflow.com/questions/6310867/why-arent-python-sets-hashable –