Dorian
Dorian

Reputation: 31

Django templates json loops

I use python/django views to get an output as:

{{ test }} 

in my template. Here is the output

{'platform': 'xbox', 'amount': '50.00', 'title': 'title of something', 'description': 'description of something'}

If I use

{% for x in test %}
{{ x }}
{% endfor %}

it outputs

platform, amount, title, description

How do I get the values and not the keys?

Upvotes: 0

Views: 507

Answers (1)

Peter DeGlopper
Peter DeGlopper

Reputation: 37319

This is just standard Python iteration over a dictionary, which defaults to iterating over the keys. If you want just the values, use {% for x in test.values %}. If you want key/value pairs, use {% for k, v in test.items %}.

Upvotes: 1

Related Questions