Skip to content

Cannot use for k, v in X with "hashmap"-like data structures #231

Answered by mitsuhiko
alpharder asked this question in Q&A
Discussion options

You must be logged in to vote

To iterate over key value pairs you need to use |items or |dictsort:

{% for key, value in my_dict|items %}
  {{ key }}: {{ value }}
{% endfor %}

Or alternatively

{% for key in my_dict %}
  {{ key }}: {{ my_dict[key] }}
{% endfor %}

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by mitsuhiko
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #230 on March 24, 2023 16:34.