【问题标题】:How to avoid auto escaping HTML tags with Jinja2如何避免使用 Jinja2 自动转义 HTML 标签
【发布时间】:2017-07-31 10:00:25
【问题描述】:

我有烧瓶、jinja2 和 python。
所以,我正在尝试显示存储为降价的文本。
我这样做

class Article(db.Entity):
...

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

在我看来,接下来我会这样做

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

在 article.html 中我只有这一行

{{text}}

因此,将数据存储在数据库中作为*im busy* 我的浏览器中有<p><em>im busy</em></p>。 我尝试使用.replace('<', '<').replace('>', '>'),但它没有任何改变。

【问题讨论】:

标签: python html jinja2


【解决方案1】:

你知道安全过滤器吗?

{{text|safe}}

Passing HTML to template using Flask/Jinja2

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-08-31
    • 2020-02-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多