我正在尝试为我的Django应用创建额外的上下文。在这种情况下,变量something_extra应该在my_template中可用。
它不起作用。没有错误,但something_extra只是没有(没有显示任何内容)
在context_processors.py中:
def extra_context(request):
return {"something_extra" :"hey"}
在观点中:
def my_view(request)
return render_to_response("my_template.html", {},context_instance=RequestContext(request))
设置中的:
TEMPLATE_CONTEXT_PROCESSORS = ("django.contrib.auth.context_processors.auth",
"django.core.context_processors.debug",
"django.core.context_processors.i18n",
"django.core.context_processors.media",
"django.core.context_processors.static",
"django.contrib.messages.context_processors.messages",
"django.core.context_processors.request",
"my_app.context_processors.extra_context", )
模板中的:
look here: {{something_extra}}