django-postman丢弃RequestContext [英] django-postman discards RequestContext
问题描述
我在每个视图中都使用context_instance = RequestContext(request)。那么可能是什么问题?
当我插入以下内容时发生:
TEMPLATE_CONTEXT_PROCESSORS =(
'django.core.context_processors.static',
'django.core.context_processors.request',
)
没有静态的,事件不会识别STATIC_URL并丢弃CSS。
TEMPLATE_CONTEXT_PROCESSORS =(
'django.core.context_processors.static',
'django.core.context_processors.request',
)
我覆盖默认的TEMPLATE_CONTEXT_PROCESSORS是不可见的:
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,)
所以我应该添加请求到这个元组的结尾。
I installed django-postman to my project. Afterwards, I saw that when I login, it logs in to the user home but then whenever I click on a link, session goes out. It wants me to re-login.
I'm using context_instance=RequestContext(request) at each view. So what could be the problem?
This happened when I inserted the following:
TEMPLATE_CONTEXT_PROCESSORS = (
'django.core.context_processors.static',
'django.core.context_processors.request',
)
Without static one, it event doesnt recognize STATIC_URL and discards CSS.
Ok I found the problem. Default django configuration doesnt have TEMPLATE_CONTEXT_PROCESSORS written in settings.py file. When I write this:
TEMPLATE_CONTEXT_PROCESSORS = (
'django.core.context_processors.static',
'django.core.context_processors.request',
)
I override the default TEMPLATE_CONTEXT_PROCESSORS which is invisible:
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",)
So I should've added request to the end of this tuple.
这篇关于django-postman丢弃RequestContext的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!