How to make Flask to unescape output when printing HTML to template in Python

When Flask passes HTML to teplate (view) it escapes text replacing symbols like “<“, “>”, etc with “&lt;”, &gt;, breaking the HTML page fro end user. To make it work properly, all that is needed is to add “|safe” to variable call in the template. For example, if var_html_data variable contains HTML, instead of

{{ var_html_data }}

one should use

{{ var_html_data|safe }}

like in the example below:

{% extends "layout.html" %}
{% block body %}
  {{ var_html_data|safe }}
{% endblock %}
  • ┬áDone!