本文整理匯總了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,
)