Python Django:';WSGIRequest&x27;对象没有属性';用户';?-认证中间件&;SessionAuthenticationMiddleware正在按顺序运行
尝试访问django管理面板时出现以下错误Python Django:';WSGIRequest&x27;对象没有属性';用户';?-认证中间件&;SessionAuthenticationMiddleware正在按顺序运行,python,django,wsgi,Python,Django,Wsgi,尝试访问django管理面板时出现以下错误 Environment: Request Method: GET Request URL: http://localhost:8000/admin/ Django Version: 1.9.8 Python Version: 2.7.10 Installed Applications: ['django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes',
Environment:
Request Method: GET
Request URL: http://localhost:8000/admin/
Django Version: 1.9.8
Python Version: 2.7.10
Installed Applications:
['django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'bookapp']
Installed Middleware:
['django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware']
Traceback:
File "/Library/Python/2.7/site-packages/django/core/handlers/base.py" in get_response
149. response = self.process_exception_by_middleware(e, request)
File "/Library/Python/2.7/site-packages/django/core/handlers/base.py" in get_response
147. response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/Library/Python/2.7/site-packages/django/contrib/admin/sites.py" in wrapper
265. return self.admin_view(view, cacheable)(*args, **kwargs)
File "/Library/Python/2.7/site-packages/django/utils/decorators.py" in _wrapped_view
149. response = view_func(request, *args, **kwargs)
File "/Library/Python/2.7/site-packages/django/views/decorators/cache.py" in _wrapped_view_func
57. response = view_func(request, *args, **kwargs)
File "/Library/Python/2.7/site-packages/django/contrib/admin/sites.py" in inner
233. if not self.has_permission(request):
File "/Library/Python/2.7/site-packages/django/contrib/admin/sites.py" in has_permission
173. return request.user.is_active and request.user.is_staff
Exception Type: AttributeError at /admin/
Exception Value: 'WSGIRequest' object has no attribute 'user'
这是我在settings.py中的中间件设置
MIDDLEWARE_CLASSES = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
我也尝试过清除缓存,比如清除迁移和删除数据库。但这对我不起作用
有人知道这里有什么问题吗?将名称
中间件更改为中间件\u类
请显示完整的回溯:单击“切换到复制和粘贴视图”在调试页面中,将文本粘贴到此处。@DanielRoseman编辑该错误页面告诉您没有安装这些中间件类;您只有普通的和csrf的。你确定你有正确的设置文件吗?是的。我也发布了一些课程,我知道你有。但是错误页面清楚地显示了与您声明的列表不同的列表。所以,你的设置没有被使用。@ PinankLakhani,你应该考虑批准这个答案。