python - jinja2: TemplateSyntaxError: expected token ',', got 'string' -


i new jinja2 , having issue using python regular expression (re). in following code bold lines have error string in them.

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

the re.search above throws following error:

jinja2.exceptions.templatesyntaxerror templatesyntaxerror: expected token ',', got 'string' 

raw python code not supported in jinja2 template syntax.

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

replace line with

{% if "error" in l %} 

can fix problem.

if logical condition more complicated, should consider defining own custom filters(which can call python code) or complicated things in view layer. go check global namespace.


Comments

Popular posts from this blog

qt - Using float or double for own QML classes -

Create Outlook appointment via C# .Net -

ios - Swift Array Resetting Itself -