1

I have a list from an mysql query that I'm trying to return in my bottle website. Is this possible? Here's what I have:

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)

This is the error that I get.

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'
Vong Ly
  • 187
  • 1
  • 1
  • 10

1 Answers1

1

Got It (took me a while...)

 % for kitchen_location in {{kitchen_locations}}:

Should be

 % for kitchen_location in kitchen_locations:

When using the % at the beginning you don't need the {{}}.

This error:

TypeError: unhashable type: 'set'

is trying to use a set literal {{kitchen_locations}} ==>

kitchen_locations in a set in another set. since set is not hash-able you got the error

Yoav Glazner
  • 7,936
  • 1
  • 19
  • 36
  • It worked! Thank you! Can you help me understand what it means for sets or lists to be hashable or unhashable? – Vong Ly Jan 14 '16 at 01:55
  • @VongLy - http://stackoverflow.com/questions/2671376/hashable-immutable and http://stackoverflow.com/questions/6310867/why-arent-python-sets-hashable – Yoav Glazner Jan 14 '16 at 05:53