django.core.context_processors.request未被添加

时间:2012-05-25 08:49:51

标签: django request

这是在我的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_PREPROCESSOR django.core.context_processors.request。任何帮助?谢谢

1 个答案:

答案 0 :(得分:4)

你错过了's'。您应该在设置文件中定义TEMPLATE_CONTEXT_PROCESSORS