本文整理汇总了Python中django.template.base.Node方法的典型用法代码示例。如果您正苦于以下问题:Python base.Node方法的具体用法?Python base.Node怎么用?Python base.Node使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django.template.base
的用法示例。
在下文中一共展示了base.Node方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: handle_token
# 需要导入模块: from django.template import base [as 别名]
# 或者: from django.template.base import Node [as 别名]
def handle_token(cls, parser, token):
"""
Class method to parse prefix node and return a Node.
"""
bits = token.split_contents()
if len(bits) < 2:
raise template.TemplateSyntaxError(
"'%s' takes at least one argument (path to file)" % bits[0])
path = parser.compile_filter(bits[1])
if len(bits) >= 2 and bits[-2] == 'as':
varname = bits[3]
else:
varname = None
return cls(varname, path)
示例2: test_tag
# 需要导入模块: from django.template import base [as 别名]
# 或者: from django.template.base import Node [as 别名]
def test_tag(self):
@self.library.tag
def func(parser, token):
return Node()
self.assertEqual(self.library.tags['func'], func)
示例3: test_tag_parens
# 需要导入模块: from django.template import base [as 别名]
# 或者: from django.template.base import Node [as 别名]
def test_tag_parens(self):
@self.library.tag()
def func(parser, token):
return Node()
self.assertEqual(self.library.tags['func'], func)
示例4: test_tag_name_arg
# 需要导入模块: from django.template import base [as 别名]
# 或者: from django.template.base import Node [as 别名]
def test_tag_name_arg(self):
@self.library.tag('name')
def func(parser, token):
return Node()
self.assertEqual(self.library.tags['name'], func)
示例5: test_tag_name_kwarg
# 需要导入模块: from django.template import base [as 别名]
# 或者: from django.template.base import Node [as 别名]
def test_tag_name_kwarg(self):
@self.library.tag(name='name')
def func(parser, token):
return Node()
self.assertEqual(self.library.tags['name'], func)
示例6: test_tag_call
# 需要导入模块: from django.template import base [as 别名]
# 或者: from django.template.base import Node [as 别名]
def test_tag_call(self):
def func(parser, token):
return Node()
self.library.tag('name', func)
self.assertEqual(self.library.tags['name'], func)
示例7: test_extends_node_repr
# 需要导入模块: from django.template import base [as 别名]
# 或者: from django.template.base import Node [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>')
示例8: iterate_with_template_sources
# 需要导入模块: from django.template import base [as 别名]
# 或者: from django.template.base import Node [as 别名]
def iterate_with_template_sources(
frames,
with_locals=True,
library_frame_context_lines=None,
in_app_frame_context_lines=None,
include_paths_re=None,
exclude_paths_re=None,
locals_processor_func=None,
):
template = None
for f in frames:
try:
frame, lineno = f
except ValueError:
# TODO how can we possibly get anything besides a (frame, lineno) tuple here???
logging.getLogger("elasticapm").error("Malformed list of frames. Frames may be missing in Kibana.")
break
f_code = getattr(frame, "f_code", None)
if f_code:
function_name = frame.f_code.co_name
if function_name == "render":
renderer = getattr(frame, "f_locals", {}).get("self")
if renderer and isinstance(renderer, Node):
if getattr(renderer, "token", None) is not None:
if hasattr(renderer, "source"):
# up to Django 1.8
yield {"lineno": renderer.token.lineno, "filename": renderer.source[0].name}
else:
template = {"lineno": renderer.token.lineno}
# Django 1.9 doesn't have the origin on the Node instance,
# so we have to get it a bit further down the stack from the
# Template instance
elif renderer and isinstance(renderer, Template):
if template and getattr(renderer, "origin", None):
template["filename"] = renderer.origin.name
yield template
template = None
yield get_frame_info(
frame,
lineno,
library_frame_context_lines=library_frame_context_lines,
in_app_frame_context_lines=in_app_frame_context_lines,
with_locals=with_locals,
include_paths_re=include_paths_re,
exclude_paths_re=exclude_paths_re,
locals_processor_func=locals_processor_func,
)