我在一个从sqlite数据库中呈现一些数据的应用程序中使用Flask.我的问题是当应用程序呈现一些内部有html的文本时,显示为文本而不是html.例如,数据库中的记录具有以下文本:
My tailor <strong>is</strong> rich
Run Code Online (Sandbox Code Playgroud)
html页面呈现为:
<html>
<!-- snip .... -->
My tailor >strong<is>/strong< rich
<!-- snip .... -->
</html>
Run Code Online (Sandbox Code Playgroud)
而且,我想要的是这个("是"字必须更大胆):
<html>
<!-- snip .... -->
My tailor <strong>is</strong> rich
<!-- snip .... -->
</html>
Run Code Online (Sandbox Code Playgroud)
有谁知道我该怎么办?
Sea*_*ira 32
如果您知道内容是安全的,只需使用safe过滤器:
{# In the Jinja template #}
{% for article in articles %}
<div class="article">{{article|safe}}</div>
{% endfor %}
Run Code Online (Sandbox Code Playgroud)