在 Django 中,每当我需要访问messages
或user
实例时,我都需要这样做:
return render_to_response('news.html', {"articles": articles}, context_instance=RequestContext(request))
有没有办法使这种默认行为?这是我的 settings.py 文件的一部分:
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.core.context_processors.tz",
"django.contrib.messages.context_processors.messages"
)
每当我想渲染模板时,我都不想指定 context_instance。