From 75a8a32f8629b47135890ac6ecda061a616d1cfc Mon Sep 17 00:00:00 2001 From: Malcolm Tredinnick Date: Sun, 18 Jun 2006 04:12:55 +0000 Subject: [PATCH] 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 --- django/template/__init__.py | 2 ++ django/template/defaulttags.py | 9 +++++++-- docs/templates.txt | 2 ++ tests/othertests/templates.py | 4 ++++ 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'),