Passing HTML to template using Flask/Jinja2


I'm building an admin for Flask and SQLAlchemy, and I want to pass the HTML for the different inputs to my view using render_template. The templating framework seems to escape the html automatically, so all <"'> are converted to html entities. How can I disable that so that the HTML renders correctly?

3/20/2014 4:54:43 PM

Accepted Answer

the ideal way is to

{{ something|safe }}

than completely turning off auto escaping.

7/16/2010 4:00:54 PM

You can also declare it HTML safe from the code:

from flask import Markup
value = Markup('<strong>The HTML String</strong>')

Then pass that value to the templates and they don't have to |safe it.

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow