本文整理汇总了Python中django.template.context.Context.dicts方法的典型用法代码示例。如果您正苦于以下问题:Python Context.dicts方法的具体用法?Python Context.dicts怎么用?Python Context.dicts使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django.template.context.Context
的用法示例。
在下文中一共展示了Context.dicts方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: render
# 需要导入模块: from django.template.context import Context [as 别名]
# 或者: from django.template.context.Context import dicts [as 别名]
def render(self, context):
def __get_dicts(context):
result = []
for context_dict in context.dicts:
if isinstance(context_dict, RequestContext) or isinstance(context_dict, Context):
result += __get_dicts(context_dict)
else:
result.append(context_dict.copy())
return result
try:
var = template.resolve_variable(self.obj, context)
except template.VariableDoesNotExist:
return ""
if not isinstance(var, models.Model):
return ""
if hasattr(var, 'get_template_root'):
template_root = 'render/%s' % var.get_template_root(self.using)
else:
template_root = 'render/%s/%s' % (var._meta.app_label,
var._meta.object_name.lower())
if self.using:
template_name = '%s__%s' % (template_root, self.using)
elif self.suffix is not None:
template_name = '%s__%s.html' % (template_root, self.suffix)
else:
template_name = '%s.html' % template_root
template_list = [
template_name,
'render/default.html',
] # We probably want access to variables added by the context processors
# so let's copy the existing context since we might not have access
# to the request object.
render_context = Context()
render_context.dicts = __get_dicts(context)
render_context['render_obj'] = var
rendered = render_to_string(template_list, render_context)
return rendered