我正在向我的模板传递一些html,如passDict["problemText"] = <p> Some html</p>
return render(response,'main/base.html',passDict)
。然后在我的html文件中显示{{problemText}}
。我得到了<p> Some html</p>
作为我的文本,而不是像我想要的那样在一段中得到Some html
。
需要将其标记为安全。
使用safe
过滤器。
{{ problemText|safe }}
或者使用mark_safe()
方法。
from django.utils.safestring import mark_safe
problemText = mark_safe("<p>Some html</p>")
阅读有关安全过滤器和mark_safe()
的文档。