Reputation: 279
I have a jinja code for python and its giving me an error it doesn't give me in python
{% for i, juice in enumerate(a['juice'] for a in television):};
alert({{ juice }});
{% endfor %};
The Error I'm getting is
expected token ',', got 'for'
Upvotes: 1
Views: 219
Reputation: 473753
You don't need to add :
at the end of the for
statements in Jinja2. And, you are not properly closing the tag - missing the %
before the }
.
Plus, there is no enumerate()
function in Jinja2, use the loop.index0
:
{% for a in television %}
{{ loop.index0 }}, {{ a["juice"] }}
{% endfor %}
If you want to use more Python in the templates, you should probably look at the Mako
engine.
Upvotes: 2