guyyug
guyyug

Reputation: 1087

Access JSON attributes from django template

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

Answers (1)

Brandon Taylor
Brandon Taylor

Reputation: 34553

Try:

{% for k, v in a.items %}
    {{ v }}
{% endfor %}

https://docs.djangoproject.com/en/1.5/ref/templates/builtins/#for

Upvotes: 8

Related Questions