Having trouble using Key Value For Loops in the Django Template system and was wondering if anyone could help. I am only able to get results if I include at the end of the for loop "values.1.items" instead of "values.items" which produces nothing.
There are many "values" and I can't for the life of me figure out why I have to specify each item numerically. I want to display all the items through this loop. Thanks for the help!
{% for key, values in obj_as_json.items %}
{% for k, v in values.1.items %}
{{ k }}: {{ v }}<br><br>
{% endfor %}
{% endfor %}
values is a list of of dictionaries rather than a dictionary or a simple list it would look something like this
values = [{'k':'v'},{'k1':'v1'},...]
you can loop over it like a list
{% for key, values in obj_as_json.items %}
{% for mydict in values %}
{%for k,v in mydict.items %}
....
alternatively you could access it by its index in the list
{% for k,v in values.1.items %}
is basically the same as
for k,v in values[1].items():
in normal python
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With