本文整理汇总了Python中django.template.base.TemplateSyntaxError方法的典型用法代码示例。如果您正苦于以下问题:Python base.TemplateSyntaxError方法的具体用法?Python base.TemplateSyntaxError怎么用?Python base.TemplateSyntaxError使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django.template.base
的用法示例。
在下文中一共展示了base.TemplateSyntaxError方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from django.template import base [as 别名]
# 或者: from django.template.base import TemplateSyntaxError [as 别名]
def __init__(self, parser, token):
tokens = token.split_contents()
self.original = parser.compile_filter(tokens[1])
self.size = parser.compile_filter(tokens[2])
self.options = {}
if tokens[-2] == 'as':
self.variable_name = tokens[-1]
else:
raise TemplateSyntaxError('get_thumbnail tag needs an variable assignment with "as"')
for option in tokens[3:-2]:
parsed_option = re.match(r'^(?P<key>[\w]+)=(?P<value>.+)$', option.strip())
if parsed_option:
key = parsed_option.group('key')
value = parser.compile_filter(parsed_option.group('value'))
self.options[key] = value
else:
raise TemplateSyntaxError('{} is invalid option syntax'.format(option))
示例2: has_permission
# 需要导入模块: from django.template import base [as 别名]
# 或者: from django.template.base import TemplateSyntaxError [as 别名]
def has_permission(parser, token):
bits = list(token.split_contents())
if len(bits) < 2:
raise TemplateSyntaxError("%r takes minimal one argument" % bits[0])
end_tag = 'end' + bits[0]
vals = []
for bit in bits[2:]:
vals.append(parser.compile_filter(bit))
nodelist_true = parser.parse(('else', end_tag))
token = parser.next_token()
if token.contents == 'else':
nodelist_false = parser.parse((end_tag,))
parser.delete_first_token()
else:
nodelist_false = NodeList()
return PermissionNode(parser.compile_filter(bits[1]), vals, nodelist_true, nodelist_false)
示例3: test_templatetag_fails_loud
# 需要导入模块: from django.template import base [as 别名]
# 或者: from django.template.base import TemplateSyntaxError [as 别名]
def test_templatetag_fails_loud(template_render_tag, template_context, settings):
settings.DEBUG = True
with pytest.raises(SiteMessageConfigurationError):
template_render_tag(
'sitemessage', 'sitemessage_prefs_table from user_prefs',
template_context({'user_prefs': 'a'}))
with pytest.raises(TemplateSyntaxError):
template_render_tag('sitemessage', 'sitemessage_prefs_table user_prefs')
示例4: __mod__
# 需要导入模块: from django.template import base [as 别名]
# 或者: from django.template.base import TemplateSyntaxError [as 别名]
def __mod__(self, other):
from django.template.base import TemplateSyntaxError
raise TemplateSyntaxError(
"Undefined variable or unknown value for: %s" % repr(other))
示例5: render
# 需要导入模块: from django.template import base [as 别名]
# 或者: from django.template.base import TemplateSyntaxError [as 别名]
def render(self, context):
from thumbnails import get_thumbnail # imported inline in order for mocking to work
if self.original and self.size:
original = self.original.resolve(context)
size = self.size.resolve(context)
options = {}
for key in self.options:
options[key] = self.options[key].resolve(context)
context[self.variable_name] = get_thumbnail(original, size, **options)
else:
raise TemplateSyntaxError()
return ''
示例6: source_error
# 需要导入模块: from django.template import base [as 别名]
# 或者: from django.template.base import TemplateSyntaxError [as 别名]
def source_error(self, source, msg):
e = TemplateSyntaxError(msg)
e.django_template_source = source
return e
示例7: gravatar
# 需要导入模块: from django.template import base [as 别名]
# 或者: from django.template.base import TemplateSyntaxError [as 别名]
def gravatar(parser, token):
try:
tag_name, email, size = token.split_contents()
except ValueError:
raise template.TemplateSyntaxError("%r tag requires email and size arguments" % token.contents.split()[0])
return GravatarUrlNode(email, size)
示例8: __mod__
# 需要导入模块: from django.template import base [as 别名]
# 或者: from django.template.base import TemplateSyntaxError [as 别名]
def __mod__(self, other):
if getattr(other, "var") in allowed_undefined_variables:
return super(InvalidString, self).__mod__(other)
from django.template.base import TemplateSyntaxError
raise TemplateSyntaxError(
'Undefined variable or unknown value for "{}" ({})'.format(other, other.var)
)
示例9: test_basic_syntax06
# 需要导入模块: from django.template import base [as 别名]
# 或者: from django.template.base import TemplateSyntaxError [as 别名]
def test_basic_syntax06(self):
"""
A variable may not contain more than one word
"""
with self.assertRaises(TemplateSyntaxError):
self.engine.get_template('basic-syntax06')
示例10: test_basic_syntax07
# 需要导入模块: from django.template import base [as 别名]
# 或者: from django.template.base import TemplateSyntaxError [as 别名]
def test_basic_syntax07(self):
"""
Raise TemplateSyntaxError for empty variable tags.
"""
with self.assertRaisesMessage(TemplateSyntaxError, 'Empty variable tag on line 1'):
self.engine.get_template('basic-syntax07')
示例11: test_basic_syntax08
# 需要导入模块: from django.template import base [as 别名]
# 或者: from django.template.base import TemplateSyntaxError [as 别名]
def test_basic_syntax08(self):
"""
Raise TemplateSyntaxError for empty variable tags.
"""
with self.assertRaisesMessage(TemplateSyntaxError, 'Empty variable tag on line 1'):
self.engine.get_template('basic-syntax08')
示例12: test_basic_syntax12
# 需要导入模块: from django.template import base [as 别名]
# 或者: from django.template.base import TemplateSyntaxError [as 别名]
def test_basic_syntax12(self):
"""
Raise TemplateSyntaxError when trying to access a variable
beginning with an underscore.
"""
with self.assertRaises(TemplateSyntaxError):
self.engine.get_template('basic-syntax12')
# Raise TemplateSyntaxError when trying to access a variable
# containing an illegal character.
示例13: test_basic_syntax13
# 需要导入模块: from django.template import base [as 别名]
# 或者: from django.template.base import TemplateSyntaxError [as 别名]
def test_basic_syntax13(self):
with self.assertRaises(TemplateSyntaxError):
self.engine.get_template('basic-syntax13')
示例14: test_basic_syntax15
# 需要导入模块: from django.template import base [as 别名]
# 或者: from django.template.base import TemplateSyntaxError [as 别名]
def test_basic_syntax15(self):
with self.assertRaises(TemplateSyntaxError):
self.engine.get_template('basic-syntax15')
示例15: test_basic_syntax16
# 需要导入模块: from django.template import base [as 别名]
# 或者: from django.template.base import TemplateSyntaxError [as 别名]
def test_basic_syntax16(self):
with self.assertRaises(TemplateSyntaxError):
self.engine.get_template('basic-syntax16')