Skip to content Skip to sidebar Skip to footer

New Lines In Flask Within {%block Content%}

So if I were to do something like {% block content %} {{variable}} {% endblock %} in my HTML, and variable is equal to 'Test test2' how come the pri

Solution 1:

Jinja2 automatically escapes special characters for you. Probably simplest way is to use safe filter:

{{ variable|safe }}

Solution 2:

If your output is escaped and you see literal <br /> text in your browser, switch off autoescaping for the variable:

{% block content %}{% autoescape false %} {{variable}} {% endautoescape %}{% endblock %}

or tell Jinja2 that the variable is safe for interpolation:

{% block content %} {{variable|safe}} {% endblock %}

Post a Comment for "New Lines In Flask Within {%block Content%}"