Jinja2: TemplateSyntaxError: expected token ',', received 'string'

I am new to Jinja2 and have a problem using python (re) regex. In the following code, I would like to highlight lines that have an error line.

  {% block content %}
    <div class="container">
      {% for l in lines %}
         {% if re.search(r"Error", l) %}  {# <<< Throws error #}
            <b> {{ l }} </b>
         {% else %}
            {{ l }} <hr>
         {% endif %}
      {% endfor %}
    </div>
 {% endblock %}

As a result, re.search throws the following error:

jinja2.exceptions.TemplateSyntaxError
TemplateSyntaxError: expected token ',', got 'string'
+4
source share
1 answer

Raw python code is not fully supported in jinja2 template syntax.

{% if re.search(r"Error", l) %}

replace this line with

{% if "Error" in l %}

can solve your problem.

, ( Python) . .

+7

Source: https://habr.com/ru/post/1598467/


All Articles