I'm using Flask in an app that render some data from a sqlite database. My problem is when the app render some text that has html inside, appear as text instead of html. For example, the record in database has the following text:
My tailor <strong>is</strong> rich
The html page render as is:
<html>
<!-- snip .... -->
My tailor >strong<is>/strong< rich
<!-- snip .... -->
</html>
And, what I want is this ("is" word has to be bolder):
<html>
<!-- snip .... -->
My tailor <strong>is</strong> rich
<!-- snip .... -->
</html>
Does anybody know how can I do that?
Jinja, also commonly referred to as "Jinja2" to specify the newest release version, is a Python template engine used to create HTML, XML or other markup formats that are returned to the user via an HTTP response.
Flask leverages Jinja2 as its template engine. You are obviously free to use a different template engine, but you still have to install Jinja2 to run Flask itself. This requirement is necessary to enable rich extensions.
If you know the content is safe, simply use the safe
filter:
{# In the Jinja template #}
{% for article in articles %}
<div class="article">{{article|safe}}</div>
{% endfor %}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With