[Fixed]-Django Template: key, value not possible in for loop

33👍

Loop through the dictionary’s items to get the keys and values:

{% for key, value in test.items %}

-1👍

Not familiar with Django. However, by default, Python iterates over the keys for a dictionary. I am also going to assume you are using Python2. To get the values, you need to do:

{% for value in test.itervalues() %}

If you want both, you need to do:

{% for key, value in test.iteritems() %}

That will give you both the key and the value.

Leave a comment