ollien
ollien

Reputation: 4766

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 <br /> test2" how come the
prints out and does not make a new line? is there a way to fix this?

Upvotes: 3

Views: 4081

Answers (2)

Martijn Pieters
Martijn Pieters

Reputation: 1123940

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 %}

Upvotes: 3

plaes
plaes

Reputation: 32746

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

{{ variable|safe }}

Upvotes: 8

Related Questions