Can I escape or delimit the "{{ }}" template braces?

310 views
Skip to first unread message

J. Marc Edwards

unread,
Dec 19, 2011, 10:35:25 AM12/19/11
to django...@googlegroups.com
I'd like to write a paragraph on my page that describes the {{ }} syntax, but the template interpreter is interpreting the braces.
--

J. Marc Edwards
Lead Architect - Semiconductor Design Portals

Nimbis Services, Inc.
Skype: (919) 747-3775
Cell:  (919) 345-1021
Fax:   (919) 882-8602

marc.e...@nimbisservices.com
www.nimbisservices.com

marc_edwards.vcf

Andre Terra

unread,
Dec 19, 2011, 10:38:34 AM12/19/11
to django...@googlegroups.com

On Mon, Dec 19, 2011 at 1:35 PM, J. Marc Edwards <marc.e...@nimbisservices.com> wrote:
I'd like to write a paragraph on my page that describes the {{ }} syntax, but the template interpreter is interpreting the braces.

 

From https://docs.djangoproject.com/en/dev/ref/templates/builtins/?from=olddocs#autoescape

autoescape

Controls the current auto-escaping behavior. This tag takes either on or off as an argument and that determines whether auto-escaping is in effect inside the block. The block is closed with an endautoescape ending tag.

When auto-escaping is in effect, all variable content has HTML escaping applied to it before placing the result into the output (but after any filters have been applied). This is equivalent to manually applying the escape filter to each variable.

The only exceptions are variables that are already marked as “safe” from escaping, either by the code that populated the variable, or because it has had the safe or escape filters applied.

Sample usage:

{% autoescape on %}
    {{ body }}
{% endautoescape %}


Cheers,
AT

Ian Clelland

unread,
Dec 19, 2011, 10:58:28 AM12/19/11
to django...@googlegroups.com


On Monday, December 19, 2011, J. Marc Edwards <marc.e...@nimbisservices.com> wrote:
> I'd like to write a paragraph on my page that describes the {{ }} syntax, but the template interpreter is interpreting the braces.

I think what you need is the {% templatetag %} tag -- it outputs template tag start and end markers.

https://docs.djangoproject.com/en/dev/ref/templates/builtins/?from=olddocs#templatetag

It can get a bit wordy, though, if your page has a lot of tags on it. If you search online, you will find that a number of people have written {% verbatim %} tags to solve just this problem.

J. Cliff Dyer

unread,
Dec 19, 2011, 11:10:31 AM12/19/11
to django...@googlegroups.com
The answer you're looking for is the "templatetag" template tag.  Essentially, it lets you specify escaped characters by name.

https://docs.djangoproject.com/en/dev/ref/templates/builtins/#templatetag

For example:

>>> from django.template import Template, Context
>>> t = Template('{% templatetag openvariable %} foo {% templatetag closevariable %}')
>>> t.render(Context())
u'{{ template_variable }}'
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django...@googlegroups.com.
To unsubscribe from this group, send email to django-users...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

Reply all
Reply to author
Forward
0 new messages