本文整理汇总了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
示例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
示例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
示例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
示例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>')