2

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'.
AFS
  • 1,433
  • 6
  • 28
  • 52

2 Answers2

6

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.

Doobeh
  • 9,280
  • 39
  • 32
3

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 %}
Community
  • 1
  • 1