Reputation: 493
I have a dictionary:
babies = {'clothes list':['a','b','c','d'], 'lots of toys': 'yes'}
Now in the template I want to do the equivalent of:
for cloth in babies['clothes list']:
print cloth
I have filter key_lookup defined. So doing this works in template:
{{ babies|key_lookup:'lots of toys' }}
But doing
{% for cloth in babies|key_lookup:'clothes list' %}
doesn't work.
The above dictionary is just an example. I can not modify the dictionary keys. key_lookup is defined as
def key_lookup(the_dict, key):
return the_dict.get(key, None)
Upvotes: 0
Views: 115
Reputation: 55678
Have you tried using with
? If it's just a syntax issue, this might work:
{% with clothes=babies|key_lookup:'clothes list' %}
{% for cloth in clothes %}
...
{% endfor %}
{% endwith %}
Upvotes: 1