sashaaero
sashaaero

Reputation: 2888

How to avoid auto escaping HTML tags with Jinja2

I have flask, jinja2 and python.
So, I'm trying to display text that is stored as markdown.
I do this

class Article(db.Entity):
...

    def html(self):
        return markdown(self.text) # from markdown import markdown

Next in my view I do this

html_text = article_.html()    
return render_template('article.html', article=article_, comments=comments, user=user, text=html_text)

And in article.html I just have this line

{{text}}

So, with data stored in db as *im busy* I have <p><em>im busy</em></p> in my browser. I tried to use .replace('&lt;', '<').replace('&gt;', '>') but it changes nothing.

Upvotes: 9

Views: 6456

Answers (1)

klim
klim

Reputation: 1269

Do you know safe filter?

{{text|safe}}

Passing HTML to template using Flask/Jinja2

Upvotes: 18

Related Questions