在Django模板中包含HTML变量而不进行转义 [英] Including HTML variable in Django template without escaping
本文介绍了在Django模板中包含HTML变量而不进行转义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有html编码的文本,其内容如下:
I have html encoded text which reads like this:
RT <a href="http://twitter.com/freuter">@freuter</a>...
我希望将其显示为html,但是我不确定是否存在可以应用于此文本的过滤器,以将html编码的文本转换回html ...
I want this displayed as html but I am not sure if there is a filter which i can apply to this text to convert the html-encoded text back to html ...
有人可以帮忙吗?
推荐答案
如丹尼尔所说,请在html中使用{{ tweet|safe }}
过滤器,或从视图中将其标记为安全.
As Daniel says, use the {{ tweet|safe }}
filter in the html, or mark it safe from the views.
使用django.template.mark_safe()
这篇关于在Django模板中包含HTML变量而不进行转义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文