当前位置: 首页>>代码示例>>Python>>正文


Python base.TemplateSyntaxError方法代码示例

本文整理汇总了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)) 
开发者ID:python-thumbnails,项目名称:python-thumbnails,代码行数:21,代码来源:thumbnails.py

示例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) 
开发者ID:matllubos,项目名称:django-is-core,代码行数:20,代码来源:permissions.py

示例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') 
开发者ID:idlesign,项目名称:django-sitemessage,代码行数:13,代码来源:test_toolbox.py

示例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)) 
开发者ID:seanbell,项目名称:opensurfaces,代码行数:6,代码来源:settings.py

示例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 '' 
开发者ID:python-thumbnails,项目名称:python-thumbnails,代码行数:16,代码来源:thumbnails.py

示例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 
开发者ID:blackye,项目名称:luscan-devel,代码行数:6,代码来源:debug.py

示例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) 
开发者ID:wooey,项目名称:Wooey,代码行数:10,代码来源:wooey_tags.py

示例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)
        ) 
开发者ID:OpenHumans,项目名称:open-humans,代码行数:11,代码来源:testing.py

示例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') 
开发者ID:nesdis,项目名称:djongo,代码行数:8,代码来源:test_basic.py

示例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') 
开发者ID:nesdis,项目名称:djongo,代码行数:8,代码来源:test_basic.py

示例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') 
开发者ID:nesdis,项目名称:djongo,代码行数:8,代码来源:test_basic.py

示例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. 
开发者ID:nesdis,项目名称:djongo,代码行数:12,代码来源:test_basic.py

示例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') 
开发者ID:nesdis,项目名称:djongo,代码行数:5,代码来源:test_basic.py

示例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') 
开发者ID:nesdis,项目名称:djongo,代码行数:5,代码来源:test_basic.py

示例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') 
开发者ID:nesdis,项目名称:djongo,代码行数:5,代码来源:test_basic.py


注:本文中的django.template.base.TemplateSyntaxError方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。