Reputation: 1087
I am trying to access JSON attributes through django template. I can access to the name of the attribute but not the value. Here is what I do:
view:
def view(request):
b= {u'1': u'xxxxx', u'2': u'yyyyy'}
a=json.loads(b)
template:
{% for val in a %}
{{ val }}
the result I see is: 1 2
I want to display xxxxx and yyyyy
(when I write {{ val.1 }} I get nothing)
Upvotes: 3
Views: 4035
Reputation: 34553
Try:
{% for k, v in a.items %}
{{ v }}
{% endfor %}
https://docs.djangoproject.com/en/1.5/ref/templates/builtins/#for
Upvotes: 8