问题
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.
回答1:
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.
来源:https://stackoverflow.com/questions/10189899/django-postman-discards-requestcontext