Reputation: 1443
I have a loop to show a list content in a flask template but I don't want to show the first character of the element , in this way works in python but not in flask
{%for file in files%}
{% f= file['path'] %}
<p> {{ f[1:] }}</p>
{% endfor %}
I get this error
TemplateSyntaxError: Encountered unknown tag 'f'. Jinja was looking for the following tags: 'endfor' or 'else'. The innermost block that needs to be closed is 'for'.
Upvotes: 2
Views: 3897
Reputation: 346
Duplicate of this question.
You have to use the {% set %}
template tag to assign variables within a jinja2 template:
{% for file in files %}
{% set f = file['path'] %}
<p>{{ f[1:] }}</p>
{% endfor %}
Upvotes: 3
Reputation: 9450
You need to set
variables if you wish to use them in that way. (Documentation).
That said— you should be able to just do {{ file['path'][1:] }}
within your for
loop.
Upvotes: 6