简体   繁体   中英

Iterate dictionary in django template

I have a dictionary

>>> filterdata
{u'data': [{u'filter': u'predictions', u'filtervalue': u'32', u'filterlevel': u'cltv', u'filtertype': u'>'}, {u'filter': u'profile', u'filtervalue': u"'TOMMY'", u'filterlevel': u'firstname', u'filtertype': u'='}]}

and i am using this to in django template

 {% for c in filterdata.data %}
     {{c}} ## print the current iterating dictionay
     {% for d in c.items %}
       {{ d.filtervalue }} ## does not print anything
     {% endfor %}
 {% endfor %}

any idea what i am doing wrong

You're iterating too much. d is the set of key-value pairs in the dict; filteritems is one of those keys, not an attribute of the pairs themselves. Remove that inner loop.

{% for c in filterdata.data %}
   {{ c.filtervalue }}
{% endfor %}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM