Reputation: 117
As I know if I put
{{ var_name }}
in django template, it will be parsed as an variable. What should I write if I want the string "{{ var_name }}" displayed in HTML file (not {{ var_name }})?
I'm not quite sure how to describe this question, so I have no idea what key word to search in Google. Thank you.
Upvotes: 0
Views: 1738
Reputation: 6147
What you want to do is called escaping.
You can substitute the brackets like this:
{
instead of {
}
instead of }
So, in your HTML code,
{{ var_name }}
will output
{{ var_name }}
.
And there's also the boring way: templatetag tag.
Upvotes: 2
Reputation: 12819
If I understand you correctly, you want to output text including literal braces.
This is done using the templatetag template tag.
For example, in your case, you will want to put:
{% templatetag openvariable %} var_name {% templatetag closevariable %}
Upvotes: 4
Reputation: 35039
If you want to use var_name
as a value for (for example) an attribute you do have to use the parentheses. For example:
{% for key, value in somedict %}
<input type="hidden" name="{{ key }}" value="{{value}}" />
{% endfor %}
Upvotes: 0