user3411846
user3411846

Reputation: 248

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

Upvotes: 1

Views: 1526

Answers (1)

Daniel Roseman
Daniel Roseman

Reputation: 600059

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 %}

Upvotes: 1

Related Questions