How do you print out the exact text "{{text}}" in a Django template?
How do you print out "{{text}}" i开发者_如何学编程n a Django template? If I type it into a Django html template it gets interpreted as the variable text. I want the actual text:
{{text}}
To appear in the html output.
To output the characters used to compose template tags, you have to use a specific template tag called templatetag
. If you want to output the {{
characters, for example, you use {% openvariable %}
and the output of that template tag would be {{
.
So for your example,
{% openvariable %} text {% closevariable %}
would output:
{{ text }}
The best way is to use the templatetag tag. However, if i recall correctly, using {{ "{{text}}" }}
will also work, this is however undocumented behaviour, so there is no real guarantee this will never break.
精彩评论