mirror of https://github.com/django/django.git
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
This commit is contained in:
parent
4540a85dda
commit
75a8a32f86
|
@ -75,6 +75,8 @@ BLOCK_TAG_START = '{%'
|
||||||
BLOCK_TAG_END = '%}'
|
BLOCK_TAG_END = '%}'
|
||||||
VARIABLE_TAG_START = '{{'
|
VARIABLE_TAG_START = '{{'
|
||||||
VARIABLE_TAG_END = '}}'
|
VARIABLE_TAG_END = '}}'
|
||||||
|
SINGLE_BRACE_START = '{'
|
||||||
|
SINGLE_BRACE_END = '}'
|
||||||
|
|
||||||
ALLOWED_VARIABLE_CHARS = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_.'
|
ALLOWED_VARIABLE_CHARS = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_.'
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
"Default tags used by the template system, available to all templates."
|
"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 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.template import get_library, Library, InvalidTemplateLibrary
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
import sys
|
import sys
|
||||||
|
@ -275,7 +275,10 @@ class TemplateTagNode(Node):
|
||||||
mapping = {'openblock': BLOCK_TAG_START,
|
mapping = {'openblock': BLOCK_TAG_START,
|
||||||
'closeblock': BLOCK_TAG_END,
|
'closeblock': BLOCK_TAG_END,
|
||||||
'openvariable': VARIABLE_TAG_START,
|
'openvariable': VARIABLE_TAG_START,
|
||||||
'closevariable': VARIABLE_TAG_END}
|
'closevariable': VARIABLE_TAG_END,
|
||||||
|
'openbrace': SINGLE_BRACE_START,
|
||||||
|
'closebrace': SINGLE_BRACE_END,
|
||||||
|
}
|
||||||
|
|
||||||
def __init__(self, tagtype):
|
def __init__(self, tagtype):
|
||||||
self.tagtype = tagtype
|
self.tagtype = tagtype
|
||||||
|
@ -809,6 +812,8 @@ def templatetag(parser, token):
|
||||||
``closeblock`` ``%}``
|
``closeblock`` ``%}``
|
||||||
``openvariable`` ``{{``
|
``openvariable`` ``{{``
|
||||||
``closevariable`` ``}}``
|
``closevariable`` ``}}``
|
||||||
|
``openbrace`` ``{``
|
||||||
|
``closebrace`` ``}``
|
||||||
================== =======
|
================== =======
|
||||||
"""
|
"""
|
||||||
bits = token.contents.split()
|
bits = token.contents.split()
|
||||||
|
|
|
@ -766,6 +766,8 @@ The argument tells which template bit to output:
|
||||||
``closeblock`` ``%}``
|
``closeblock`` ``%}``
|
||||||
``openvariable`` ``{{``
|
``openvariable`` ``{{``
|
||||||
``closevariable`` ``}}``
|
``closevariable`` ``}}``
|
||||||
|
``openbrace`` ``{``
|
||||||
|
``closebrace`` ``}``
|
||||||
================== =======
|
================== =======
|
||||||
|
|
||||||
widthratio
|
widthratio
|
||||||
|
|
|
@ -499,6 +499,10 @@ TEMPLATE_TESTS = {
|
||||||
'templatetag04': ('{% templatetag closevariable %}', {}, '}}'),
|
'templatetag04': ('{% templatetag closevariable %}', {}, '}}'),
|
||||||
'templatetag05': ('{% templatetag %}', {}, template.TemplateSyntaxError),
|
'templatetag05': ('{% templatetag %}', {}, template.TemplateSyntaxError),
|
||||||
'templatetag06': ('{% templatetag foo %}', {}, 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 ########################################################
|
### WIDTHRATIO TAG ########################################################
|
||||||
'widthratio01': ('{% widthratio a b 0 %}', {'a':50,'b':100}, '0'),
|
'widthratio01': ('{% widthratio a b 0 %}', {'a':50,'b':100}, '0'),
|
||||||
|
|
Loading…
Reference in New Issue