这是在我的 settings.py 中定义的
TEMPLATE_CONTEXT_PROCESSOR = (
"django.core.context_processors.request", # <- HERE
"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.core.context_processors.tz",
"django.contrib.messages.context_processors.messages",
)
这是在我的视图文件中:
def home(request):
ctx = {}
request.session['test'] = 1
return render(request, 'home.html', ctx)
# return render_to_response('home.html', ctx,
# context_instance=RequestContext(request))
如果我尝试从模板访问请求对象(例如{{ request.session.test }}
,没有显示任何内容。Django 调试工具栏显示在 CONTEXT_PREPROCESSORdjango.core.context_processors.request
中未添加。任何帮助?谢谢