Hello.
This is about Python Django.
In the views.py file in the function, I pass the dictionary to the template:

array = {'Bob': 10, 'Alex': 12} 

In the pattern in the loop, I output this data like this:

 {% for i in array %} {{ i }} {% endfor %} 

But this is how I get only the key: but I also need to get the value.
How can I do this? Indeed, in the template, the capabilities of the loop are very limited, and I cannot write this:

 {% for i in array.items() %} ... 

There will be an error.
What to do?
Thank you in advance!

    1 answer 1

    Just items without brackets:

     {% for key, value in array.items %} {{ key }} = {{ value }}<br/> {% endfor %} 

    And I can also advise to switch to Jinja2 template, there is almost nothing limited and almost full python in templates.

    • Anyway, the same thing. (error) - Mistin
    • What kind of mistake? - andreymal
    • Above it says: 'int' object is not iterable. And below the html template code is shown with the highlighted line: {% for key, value in test.items%} - Mistin
    • Inaccurate copy-paste of my code, or what? Replace test with array? - andreymal
    • No, in my code I did everything right. Just here the names for the variables changed, so that it was clear to you. - Mistin