本文整理汇总了Python中django.template.context.Context.push方法的典型用法代码示例。如果您正苦于以下问题:Python Context.push方法的具体用法?Python Context.push怎么用?Python Context.push使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django.template.context.Context
的用法示例。
在下文中一共展示了Context.push方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: render
# 需要导入模块: from django.template.context import Context [as 别名]
# 或者: from django.template.context.Context import push [as 别名]
def render(self, context=None, request=None):
# TODO: require context to be a dict -- through a deprecation path?
if not isinstance(context, Context):
if request is None:
context = Context(context)
else:
# The following pattern is required to ensure values from
# context override those from template context processors.
original_context = context
context = RequestContext(request)
if original_context:
context.push(original_context)
return self.template.render(context)
示例2: home
# 需要导入模块: from django.template.context import Context [as 别名]
# 或者: from django.template.context.Context import push [as 别名]
def home(request):
c = Context()
menus = Menu.objects.all()
menu_list = []
for menu in menus.values():
menu_list.append(menu['menu'])
c['menu_list'] = menu_list
contents = Content.objects.all()
content_list = []
#for content in contents.values():
c.push()
return render(request, 'Base.html', c)
示例3: render
# 需要导入模块: from django.template.context import Context [as 别名]
# 或者: from django.template.context.Context import push [as 别名]
def render(self, context=None, request=None):
# A deprecation path is required here to cover the following usage:
# >>> from django.template import Context
# >>> from django.template.loader import get_template
# >>> template = get_template('hello.html')
# >>> template.render(Context({'name': 'world'}))
# In Django 1.7 get_template() returned a django.template.Template.
# In Django 1.8 it returns a django.template.backends.django.Template.
# In Django 2.0 the isinstance checks should be removed. If passing a
# Context or a RequestContext works by accident, it won't be an issue
# per se, but it won't be officially supported either.
if isinstance(context, RequestContext):
if request is not None and request is not context.request:
raise ValueError(
"render() was called with a RequestContext and a request "
"argument which refer to different requests. Make sure "
"that the context argument is a dict or at least that "
"the two arguments refer to the same request.")
warnings.warn(
"render() must be called with a dict, not a RequestContext.",
RemovedInDjango20Warning, stacklevel=2)
elif isinstance(context, Context):
warnings.warn(
"render() must be called with a dict, not a Context.",
RemovedInDjango20Warning, stacklevel=2)
else:
if request is None:
context = Context(context)
else:
# The following pattern is required to ensure values from
# context override those from template context processors.
original_context = context
context = RequestContext(request)
if original_context:
context.push(original_context)
return self.template.render(context)
示例4: SortedDict
# 需要导入模块: from django.template.context import Context [as 别名]
# 或者: from django.template.context.Context import push [as 别名]
if verbosity > 0:
log.write("Found 'compress' tags in:\n\t" +
"\n\t".join((t.template_name
for t in compressor_nodes.keys())) + "\n")
log.write("Compressing... ")
count = 0
results = []
offline_manifest = SortedDict()
for template, nodes in compressor_nodes.iteritems():
context = Context(settings.COMPRESS_OFFLINE_CONTEXT)
template._log = log
template._log_verbosity = verbosity
for node in nodes:
context.push()
compiled_node = env.compile(jinja2.nodes.Template(node.body))
context.update(jingo.register.env.globals)
context.update(jingo.register.env.filters)
key = get_offline_hexdigest(
Template.from_code(
jingo.register.env,
compiled_node,
{}
).render(context))
try:
context['compress_forced'] = True
compiled_node = env.compile(jinja2.nodes.Template([node]))
result = Template.from_code(
env,