本文整理匯總了Python中django.template.defaulttags.token_kwargs方法的典型用法代碼示例。如果您正苦於以下問題:Python defaulttags.token_kwargs方法的具體用法?Python defaulttags.token_kwargs怎麽用?Python defaulttags.token_kwargs使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類django.template.defaulttags
的用法示例。
在下文中一共展示了defaulttags.token_kwargs方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: include_block
# 需要導入模塊: from django.template import defaulttags [as 別名]
# 或者: from django.template.defaulttags import token_kwargs [as 別名]
def include_block(parser, token):
"""
Render the passed item of StreamField content, passing the current template context
if there's an identifiable way of doing so (i.e. if it has a `render_as_block` method).
"""
tokens = token.split_contents()
try:
tag_name = tokens.pop(0)
block_var_token = tokens.pop(0)
except IndexError:
raise template.TemplateSyntaxError("%r tag requires at least one argument" % tag_name)
block_var = parser.compile_filter(block_var_token)
if tokens and tokens[0] == 'with':
tokens.pop(0)
extra_context = token_kwargs(tokens, parser)
else:
extra_context = None
use_parent_context = True
if tokens and tokens[0] == 'only':
tokens.pop(0)
use_parent_context = False
if tokens:
raise template.TemplateSyntaxError("Unexpected argument to %r tag: %r" % (tag_name, tokens[0]))
return IncludeBlockNode(block_var, extra_context, use_parent_context)
示例2: __render_helper
# 需要導入模塊: from django.template import defaulttags [as 別名]
# 或者: from django.template.defaulttags import token_kwargs [as 別名]
def __render_helper(parser, token):
tokens = token.split_contents()
try:
tag_name = tokens.pop(0)
block_var_token = tokens.pop(0)
except IndexError:
raise template.TemplateSyntaxError("%r tag requires at least one argument" % tag_name)
block_var = parser.compile_filter(block_var_token)
if tokens and tokens[0] == 'with':
tokens.pop(0)
extra_context = token_kwargs(tokens, parser)
else:
extra_context = None
use_parent_context = True
if tokens and tokens[0] == 'only':
tokens.pop(0)
use_parent_context = False
if tokens:
raise template.TemplateSyntaxError("Unexpected argument to %r tag: %r" % (tag_name, tokens[0]))
return HyperNode(block_var, extra_context, use_parent_context)