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


Python loader_tags.ExtendsNode方法代码示例

本文整理汇总了Python中django.template.loader_tags.ExtendsNode方法的典型用法代码示例。如果您正苦于以下问题:Python loader_tags.ExtendsNode方法的具体用法?Python loader_tags.ExtendsNode怎么用?Python loader_tags.ExtendsNode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在django.template.loader_tags的用法示例。


在下文中一共展示了loader_tags.ExtendsNode方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: clean_content

# 需要导入模块: from django.template import loader_tags [as 别名]
# 或者: from django.template.loader_tags import ExtendsNode [as 别名]
def clean_content(self):
        content = self.cleaned_data.get('content')

        try:
            template = Template(content)

            if template.nodelist.get_nodes_by_type(IncludeNode):
                include_tag_not_allowed = ValidationError(
                    gettext('Include blocks are not allowed.'),
                    code='include_tag_not_allowed'
                )
                self.add_error('content', include_tag_not_allowed)

            if template.nodelist.get_nodes_by_type(ExtendsNode):
                extends_tag_not_allowed = ValidationError(
                    gettext('Extends blocks are not allowed.'),
                    code='extends_tag_not_allowed'
                )
                self.add_error('content', extends_tag_not_allowed)

        except TemplateSyntaxError as tse:
            template_syntax_error = ValidationError(str(tse), code='template_syntax_error')
            self.add_error('content', template_syntax_error)

        return content 
开发者ID:vitorfs,项目名称:colossus,代码行数:27,代码来源:forms.py

示例2: _get_blocks

# 需要导入模块: from django.template import loader_tags [as 别名]
# 或者: from django.template.loader_tags import ExtendsNode [as 别名]
def _get_blocks(self, nodelist, context):
        blocks = {}
        for node in nodelist:
            if isinstance(node, ExtendsNode):
                parent = node.get_parent(context)
                blocks.update(self._get_blocks(parent.nodelist, context))
        blocks.update({
            node.name: node for node in nodelist.get_nodes_by_type(BlockNode)
        })
        return blocks 
开发者ID:sunscrapers,项目名称:django-templated-mail,代码行数:12,代码来源:mail.py

示例3: resolve_blocks

# 需要导入模块: from django.template import loader_tags [as 别名]
# 或者: from django.template.loader_tags import ExtendsNode [as 别名]
def resolve_blocks(template, context):
    '''
    Return a BlockContext instance of all the {% block %} tags in the template.

    If template is a string, it will be resolved through get_template
    '''
    try:
        blocks = context.render_context[BLOCK_CONTEXT_KEY]
    except KeyError:
        blocks = context.render_context[BLOCK_CONTEXT_KEY] = BlockContext()

    # If it's just the name, resolve into template
    if isinstance(template, str):
        template = get_template(template)

    # For Django 1.8 compatibility
    template = getattr(template, 'template', template)

    # Add this templates blocks as the first
    local_blocks = {
        block.name: block
        for block in template.nodelist.get_nodes_by_type(BlockNode)
    }
    blocks.add_blocks(local_blocks)

    # Do we extend a parent template?
    extends = template.nodelist.get_nodes_by_type(ExtendsNode)
    if extends:
        # Can only have one extends in a template
        extends_node = extends[0]

        # Get the parent, and recurse
        parent_template = extends_node.get_parent(context)
        resolve_blocks(parent_template, context)

    return blocks 
开发者ID:funkybob,项目名称:django-sniplates,代码行数:38,代码来源:sniplates.py

示例4: _get_template_variables

# 需要导入模块: from django.template import loader_tags [as 别名]
# 或者: from django.template.loader_tags import ExtendsNode [as 别名]
def _get_template_variables(template):
    """
    Extracts all the variable node tokens of the given template.
    This gets worked out recursively by extracting nodes from possible
    parent templates via the extension nodes.
    """
    var_nodes = template.nodelist.get_nodes_by_type(VariableNode)
    template_vars = [_v.filter_expression.token for _v in var_nodes]

    for ext_node in template.nodelist.get_nodes_by_type(ExtendsNode):
        template_vars += _get_template_variables(
            ext_node.get_parent(ext_node.parent_name))

    return template_vars 
开发者ID:vitorfs,项目名称:colossus,代码行数:16,代码来源:utils.py

示例5: test_extends_node_repr

# 需要导入模块: from django.template import loader_tags [as 别名]
# 或者: from django.template.loader_tags import ExtendsNode [as 别名]
def test_extends_node_repr(self):
        extends_node = ExtendsNode(
            nodelist=NodeList([]),
            parent_name=Node(),
            template_dirs=[],
        )
        self.assertEqual(repr(extends_node), '<ExtendsNode: extends None>') 
开发者ID:nesdis,项目名称:djongo,代码行数:9,代码来源:test_extends.py


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