本文介绍了从Django 1.3升级到1.9时,“ WSGIRequest”对象没有属性“ session”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
类似于此问题 WSGIRequest对象没有属性 session
但是我的MIDDLEWARE类的顺序正确。
But my MIDDLEWARE classes are in the correct order.
INSTALLED_APPS = [
'django.contrib.sessions',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.messages',
'django.contrib.staticfiles',
'membership',
'treebeard',
'haystack',
'reversion',
]
MIDDLEWARE = [
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.security.SecurityMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
我要重定向到登录
url(r'^$', RedirectView.as_view(url='login/')),
url(r'^login/$', 'membership.views.loginView', name='login'),
,然后
def loginView(request):
a = request.session
抛出错误
推荐答案
MIDDLEWARE
是1.10中的新设置,它将替换旧的 MIDDLEWARE_CLASSES
。
MIDDLEWARE
is a new setting in 1.10 that will replace the old MIDDLEWARE_CLASSES
.
由于您当前使用的是1.9,Django无法识别 MIDDLEWARE
设置。您应该改用 MIDDLEWARE_CLASSES
设置:
Since you're currently on 1.9, Django doesn't recognize the MIDDLEWARE
setting. You should use the MIDDLEWARE_CLASSES
setting instead:
MIDDLEWARE_CLASSES = [
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.security.SecurityMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
这篇关于从Django 1.3升级到1.9时,“ WSGIRequest”对象没有属性“ session”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!