Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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
  • Loading branch information...
commit 75a8a32f8629b47135890ac6ecda061a616d1cfc 1 parent 4540a85
Malcolm Tredinnick authored June 18, 2006
2  django/template/__init__.py
@@ -75,6 +75,8 @@
75 75
 BLOCK_TAG_END = '%}'
76 76
 VARIABLE_TAG_START = '{{'
77 77
 VARIABLE_TAG_END = '}}'
  78
+SINGLE_BRACE_START = '{'
  79
+SINGLE_BRACE_END = '}'
78 80
 
79 81
 ALLOWED_VARIABLE_CHARS = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_.'
80 82
 
9  django/template/defaulttags.py
... ...
@@ -1,7 +1,7 @@
1 1
 "Default tags used by the template system, available to all templates."
2 2
 
3 3
 from django.template import Node, NodeList, Template, Context, resolve_variable
4  
-from django.template import TemplateSyntaxError, VariableDoesNotExist, BLOCK_TAG_START, BLOCK_TAG_END, VARIABLE_TAG_START, VARIABLE_TAG_END
  4
+from django.template import TemplateSyntaxError, VariableDoesNotExist, BLOCK_TAG_START, BLOCK_TAG_END, VARIABLE_TAG_START, VARIABLE_TAG_END, SINGLE_BRACE_START, SINGLE_BRACE_END
5 5
 from django.template import get_library, Library, InvalidTemplateLibrary
6 6
 from django.conf import settings
7 7
 import sys
@@ -275,7 +275,10 @@ class TemplateTagNode(Node):
275 275
     mapping = {'openblock': BLOCK_TAG_START,
276 276
                'closeblock': BLOCK_TAG_END,
277 277
                'openvariable': VARIABLE_TAG_START,
278  
-               'closevariable': VARIABLE_TAG_END}
  278
+               'closevariable': VARIABLE_TAG_END,
  279
+               'openbrace': SINGLE_BRACE_START,
  280
+               'closebrace': SINGLE_BRACE_END,
  281
+               }
279 282
 
280 283
     def __init__(self, tagtype):
281 284
         self.tagtype = tagtype
@@ -809,6 +812,8 @@ def templatetag(parser, token):
809 812
         ``closeblock``      ``%}``
810 813
         ``openvariable``    ``{{``
811 814
         ``closevariable``   ``}}``
  815
+        ``openbrace``       ``{``
  816
+        ``closebrace``      ``}``
812 817
         ==================  =======
813 818
     """
814 819
     bits = token.contents.split()
2  docs/templates.txt
@@ -766,6 +766,8 @@ The argument tells which template bit to output:
766 766
     ``closeblock``      ``%}``
767 767
     ``openvariable``    ``{{``
768 768
     ``closevariable``   ``}}``
  769
+    ``openbrace``       ``{``
  770
+    ``closebrace``      ``}``
769 771
     ==================  =======
770 772
 
771 773
 widthratio
4  tests/othertests/templates.py
@@ -499,6 +499,10 @@ def method(self):
499 499
     'templatetag04': ('{% templatetag closevariable %}', {}, '}}'),
500 500
     'templatetag05': ('{% templatetag %}', {}, template.TemplateSyntaxError),
501 501
     'templatetag06': ('{% templatetag foo %}', {}, template.TemplateSyntaxError),
  502
+    'templatetag07': ('{% templatetag openbrace %}', {}, '{'),
  503
+    'templatetag08': ('{% templatetag closebrace %}', {}, '}'),
  504
+    'templatetag09': ('{% templatetag openbrace %}{% templatetag openbrace %}', {}, '{{'),
  505
+    'templatetag10': ('{% templatetag closebrace %}{% templatetag closebrace %}', {}, '}}'),
502 506
 
503 507
     ### WIDTHRATIO TAG ########################################################
504 508
     'widthratio01': ('{% widthratio a b 0 %}', {'a':50,'b':100}, '0'),

0 notes on commit 75a8a32

Please sign in to comment.
Something went wrong with that request. Please try again.