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


Python loader_tags.BlockNode方法代码示例

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


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

示例1: ensure_templates_instrumented

# 需要导入模块: from django.template import loader_tags [as 别名]
# 或者: from django.template.loader_tags import BlockNode [as 别名]
def ensure_templates_instrumented():
    global templates_instrumented
    if templates_instrumented:
        return
    templates_instrumented = True

    @trace_method(Template)
    def __init__(self, *args, **kwargs):
        name = args[2] if len(args) >= 3 else "<Unknown Template>"
        return ("Template/Compile", {"name": name})

    @trace_method(Template)
    def render(self, *args, **kwargs):
        name = self.name if self.name is not None else "<Unknown Template>"
        return ("Template/Render", {"name": name})

    @trace_method(BlockNode, "render")
    def render_block(self, *args, **kwargs):
        return ("Block/Render", {"name": self.name})

    logger.debug("Monkey patched Templates") 
开发者ID:scoutapp,项目名称:scout_apm_python,代码行数:23,代码来源:template.py

示例2: _get_blocks

# 需要导入模块: from django.template import loader_tags [as 别名]
# 或者: from django.template.loader_tags import BlockNode [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 BlockNode [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_blocks

# 需要导入模块: from django.template import loader_tags [as 别名]
# 或者: from django.template.loader_tags import BlockNode [as 别名]
def get_template_blocks(template):
    nodes = template.nodelist.get_nodes_by_type(BlockNode)
    blocks = OrderedDict()
    for node in nodes:
        blocks[node.name] = get_block_source(template.source, node.name)
    return blocks 
开发者ID:vitorfs,项目名称:colossus,代码行数:8,代码来源:utils.py

示例5: walk_nodes

# 需要导入模块: from django.template import loader_tags [as 别名]
# 或者: from django.template.loader_tags import BlockNode [as 别名]
def walk_nodes(self, node, block_name=None):
        for node in getattr(node, "nodelist", []):
            if isinstance(node, BlockNode):
                block_name = node.name
            if isinstance(node, CompressorNode):
                node._block_name = block_name
                yield node
            else:
                for node in self.walk_nodes(node, block_name=block_name):
                    yield node 
开发者ID:canvasnetworks,项目名称:canvas,代码行数:12,代码来源:compress.py


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