将模板变量呈现为 HTML [英] Rendering a template variable as HTML
本文介绍了将模板变量呈现为 HTML的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用消息"界面将消息传递给用户,如下所示:
I use the 'messages' interface to pass messages to user like this:
request.user.message_set.create(message=message)
我想在我的 {{ message }}
变量中包含 html 并在不转义模板中的标记的情况下呈现它.
I would like to include html in my {{ message }}
variable and render it without escaping the markup in the template.
推荐答案
如果您不希望 HTML 被转义,请查看 safe
过滤器和 autoescape
> 标签:
If you don't want the HTML to be escaped, look at the safe
filter and the autoescape
tag:
safe
:
{{ myhtml |safe }}
{% autoescape off %}
{{ myhtml }}
{% endautoescape %}
这篇关于将模板变量呈现为 HTML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文