我如何正确呈现以下内容?
<pre>
<code class="language-markdown">
{% autoescape off %}
<Item>hello</Item>
{% endautoescape %}
</code>
</pre>
基本上,我希望它显示xml,如:
<Item>Hello</Item>
不要试图剥离标签。相反,它只打印没有标签的“Hello”。请注意,verbatim
标记对我来说也不起作用。
答案 0 :(得分:0)
使用django.utils.html.escape
https://docs.djangoproject.com/en/1.10/ref/utils/#django.utils.html.escape
或者编写一个模板标签,使用此功能进行转义。
from django import template
from django.utils.html import escape
register = template.Library()
@register.filter
def escape_html(value):
return escape(value)