python - Render HTML tags from variable without escaping -
this question has answer here:
- passing html template using flask/jinja2 3 answers
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 }} '< text here >' 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
Post a Comment