Python Return Bottle 中的列表
Python Return a list in Bottle
我有一个来自 mysql 查询的列表,我正在尝试 return 在我的瓶子网站上。这可能吗?这是我拥有的:
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'
知道了(花了我一段时间...)
% for kitchen_location in {{kitchen_locations}}:
应该是
% for kitchen_location in kitchen_locations:
在开头使用 % 时不需要 {{}}。
这个错误:
TypeError: unhashable type: 'set'
正在尝试使用集合文字 {{kitchen_locations}} ==>
kitchen_locations一套在另一套。因为 set 不是 hash-able 你得到了错误
我有一个来自 mysql 查询的列表,我正在尝试 return 在我的瓶子网站上。这可能吗?这是我拥有的:
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'
知道了(花了我一段时间...)
% for kitchen_location in {{kitchen_locations}}:
应该是
% for kitchen_location in kitchen_locations:
在开头使用 % 时不需要 {{}}。
这个错误:
TypeError: unhashable type: 'set'
正在尝试使用集合文字 {{kitchen_locations}} ==>
kitchen_locations一套在另一套。因为 set 不是 hash-able 你得到了错误