문제

I am trying a simple continue inside a for-loop in Flask with jinja2

{% for num in range(0,10) %}
  {% if num%2 == 0 %}
    {% print num %}
  {% else %}
    {% continue %}
  {% endif %}

and i get this error

TemplateSyntaxError: Encountered unknown tag 'continue'. Jinja was looking for the following tags: 'endif'. The innermost block that needs to be closed is 'if'.

Here is the jinja2 documentation that i followed... http://jinja.pocoo.org/docs/templates/#loop-controls

도움이 되었습니까?

해결책

You need to add the loop controls extension for Jinja 2 to your app:

app.jinja_env.add_extension('jinja2.ext.loopcontrols')
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top