python - Render HTML tags from variable without escaping -


this question has answer here:

i have html content want pass template render. however, escapes tags use html entities (<), show code rather markup. how can render html passed template?

tags = """<p>some text here</p>""" render_template ('index.html',tags=tags) 
{{ tags }} '&lt; text here &gt;' 

i want paragraph text though.

some text here 

use jinja2 safe filter:

{{ tags | safe }} 

safe filter tells template engine not auto-escape string (because escaped manually or you're sure string safe). so, if string introduced user , didn't escape it, rise security problems ("don't trust user").

edit

as @davidism pointed there method - recomended 1 - pass html template: using markup object in python code wrap html code want pass template.

tags = markup("<p>some text here</p>") 

and in template use:

{{ tags }} 

which print

some text here


Comments

Popular posts from this blog

qt - Using float or double for own QML classes -

Create Outlook appointment via C# .Net -

ios - Swift Array Resetting Itself -