Skip to content Skip to sidebar Skip to footer

How To Loop Dictionary With Multiple Values In Jinja?

I have a dictionary like so: {'a': [Object, 0], 'b': [Object, 1] } Where object is an actual object with multiple attributes. I'm trying to a check on each key to see if the second

Solution 1:

Use iteritems to iterate through your dictionary:

{% for key, value in follower_list.items %}
    {% if value.1 == 0 %}
        <p>Hello</p>
    {% else %}
        <p>Goodbye</p>
{% endfor %}

Check this docs.

Solution 2:

Try using this method:

{% forkey, value in follower_list.items() %}
    {% key %}
    {% value %}

This calls the items function on the dictionary letting you iterate through all the keys and values of the dictionary.

Post a Comment for "How To Loop Dictionary With Multiple Values In Jinja?"