django-postman丢弃RequestContext [英] django-postman discards RequestContext

查看:454
本文介绍了django-postman丢弃RequestContext的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将django-postman安装到我的项目中。之后,我看到当登录时,它登录到用户家,但是当我点击一个链接,会话出来。它要我重新登录。



我在每个视图中都使用context_instance = RequestContext(request)。那么可能是什么问题?



当我插入以下内容时发生:

  TEMPLATE_CONTEXT_PROCESSORS =(
'django.core.context_processors.static',
'django.core.context_processors.request',

没有静态的,事件不会识别STATIC_URL并丢弃CSS。

解决方案好,我发现问题。缺省django配置没有在settings.py文件中写入TEMPLATE_CONTEXT_PROCESSORS。当我写这个:

  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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆