Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I make this loop with Jinja2?

Tags:

python

jinja2

With Jinja2, how can I make an iteration like the folllowing which works with django and not Jinja:

{% for key,value in location_map_india.items %}
{{value.name}}
{% endfor %}

The above is valid django but with Jinja2 it returns an error message

TypeError: 'builtin_function_or_method' object is not iterable

Thanks for any advice

like image 598
Niklas Rosencrantz Avatar asked Nov 02 '11 03:11

Niklas Rosencrantz


1 Answers

In Jinja2, functions and methods must be explicitly called.

{% for key,value in location_map_india.items() %}
{{value.name}}
{% endfor %}
like image 53
icktoofay Avatar answered Sep 29 '22 14:09

icktoofay