Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jinja2 template from Flask is failing to render CONTINUE statement

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

like image 598
Rakib Avatar asked May 16 '13 23:05

Rakib


People also ask

What is the difference between Jinja and Jinja2?

from_string . Jinja 2 provides a Template class that can be used to do the same, but with optional additional configuration. Jinja 1 performed automatic conversion of bytes in a given encoding into unicode objects.


1 Answers

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

app.jinja_env.add_extension('jinja2.ext.loopcontrols')
like image 157
bsa Avatar answered Oct 23 '22 08:10

bsa