summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMalcolm Tredinnick <malcolm.tredinnick@gmail.com>2006-06-18 04:12:55 +0000
committerMalcolm Tredinnick <malcolm.tredinnick@gmail.com>2006-06-18 04:12:55 +0000
commit75a8a32f8629b47135890ac6ecda061a616d1cfc (patch)
treeb0bd5f35ffd7c1d48e334b41517b8a55ad11795d
parent4540a85ddabd9303955b88f5f727a7ede6161253 (diff)
Fixed #2181 -- allow '{' and '}' to be escaped via {% templatetag ... %}.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@3138 bcc190cf-cafb-0310-a4f2-bffc1f526a37
-rw-r--r--django/template/__init__.py2
-rw-r--r--django/template/defaulttags.py9
-rw-r--r--docs/templates.txt2
-rw-r--r--tests/othertests/templates.py4
4 files changed, 15 insertions, 2 deletions
diff --git a/django/template/__init__.py b/django/template/__init__.py
index 028d23f251..08f433fec9 100644
--- a/django/template/__init__.py
+++ b/django/template/__init__.py
@@ -75,6 +75,8 @@ BLOCK_TAG_START = '{%'
BLOCK_TAG_END = '%}'
VARIABLE_TAG_START = '{{'
VARIABLE_TAG_END = '}}'
+SINGLE_BRACE_START = '{'
+SINGLE_BRACE_END = '}'
ALLOWED_VARIABLE_CHARS = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_.'
diff --git a/django/template/defaulttags.py b/django/template/defaulttags.py
index 50a6da68f4..8b52b70cda 100644
--- a/django/template/defaulttags.py
+++ b/django/template/defaulttags.py
@@ -1,7 +1,7 @@
"Default tags used by the template system, available to all templates."
from django.template import Node, NodeList, Template, Context, resolve_variable
-from django.template import TemplateSyntaxError, VariableDoesNotExist, BLOCK_TAG_START, BLOCK_TAG_END, VARIABLE_TAG_START, VARIABLE_TAG_END
+from django.template import TemplateSyntaxError, VariableDoesNotExist, BLOCK_TAG_START, BLOCK_TAG_END, VARIABLE_TAG_START, VARIABLE_TAG_END, SINGLE_BRACE_START, SINGLE_BRACE_END
from django.template import get_library, Library, InvalidTemplateLibrary
from django.conf import settings
import sys
@@ -275,7 +275,10 @@ class TemplateTagNode(Node):
mapping = {'openblock': BLOCK_TAG_START,
'closeblock': BLOCK_TAG_END,
'openvariable': VARIABLE_TAG_START,
- 'closevariable': VARIABLE_TAG_END}
+ 'closevariable': VARIABLE_TAG_END,
+ 'openbrace': SINGLE_BRACE_START,
+ 'closebrace': SINGLE_BRACE_END,
+ }
def __init__(self, tagtype):
self.tagtype = tagtype
@@ -809,6 +812,8 @@ def templatetag(parser, token):
``closeblock`` ``%}``
``openvariable`` ``{{``
``closevariable`` ``}}``
+ ``openbrace`` ``{``
+ ``closebrace`` ``}``
================== =======
"""
bits = token.contents.split()
diff --git a/docs/templates.txt b/docs/templates.txt
index 69251df8bb..5f397c5a60 100644
--- a/docs/templates.txt
+++ b/docs/templates.txt
@@ -766,6 +766,8 @@ The argument tells which template bit to output:
``closeblock`` ``%}``
``openvariable`` ``{{``
``closevariable`` ``}}``
+ ``openbrace`` ``{``
+ ``closebrace`` ``}``
================== =======
widthratio
diff --git a/tests/othertests/templates.py b/tests/othertests/templates.py
index 47504d6ffd..96ad330917 100644
--- a/tests/othertests/templates.py
+++ b/tests/othertests/templates.py
@@ -499,6 +499,10 @@ TEMPLATE_TESTS = {
'templatetag04': ('{% templatetag closevariable %}', {}, '}}'),
'templatetag05': ('{% templatetag %}', {}, template.TemplateSyntaxError),
'templatetag06': ('{% templatetag foo %}', {}, template.TemplateSyntaxError),
+ 'templatetag07': ('{% templatetag openbrace %}', {}, '{'),
+ 'templatetag08': ('{% templatetag closebrace %}', {}, '}'),
+ 'templatetag09': ('{% templatetag openbrace %}{% templatetag openbrace %}', {}, '{{'),
+ 'templatetag10': ('{% templatetag closebrace %}{% templatetag closebrace %}', {}, '}}'),
### WIDTHRATIO TAG ########################################################
'widthratio01': ('{% widthratio a b 0 %}', {'a':50,'b':100}, '0'),