Django管理员错误"WSGIRequest"对象没有属性"user" [英] Django admin error 'WSGIRequest' object has no attribute 'user
问题描述
我正在练习Django,当我尝试去 http://localhost/admin/时,我得到了出现以下错误,我已经检查了settings.py和MIDDLEWARE_CLASSES是否存在,是否还有其他原因导致我收到此消息.
/admin/中的 AttributeError"WSGIRequest"对象没有属性"user"请求方法:GET要求网址:http://localhost/admin/Django版本:2.0异常类型:AttributeError异常值:"WSGIRequest"对象没有属性"user"例外位置:has_permission,第186行中的/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/contrib/admin/sites.pyPython可执行文件:/usr/local/bin/python3的Python版本:3.6.1Python路径:['/Users/yasserhussain/learning_site','/Library/Frameworks/Python.framework/Versions/3.6/lib/python36.zip','/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6','/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/lib-dynload','/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages']服务器时间:2018年1月4日,星期四00:17:34 +0000
设置中MIDDLEWARE的内容
MIDDLEWARE =('django.contrib.sessions.middleware.SessionMiddleware','django.middleware.common.CommonMiddleware','django.middleware.csrf.CsrfViewMiddleware','django.contrib.messages.middleware.MessageMiddleware','django.middleware.clickjacking.XFrameOptionsMiddleware','django.middleware.security.SecurityMiddleware',)
Django 2.0放弃了对 MIDDLEWARE_CLASSES
中的旧式中间件类的支持.com/en/2.0/releases/2.0/"rel =" noreferrer>更改日志,最后一项
如果仅使用标准中间件,升级将很简单,如 django.contrib.auth
已正确安装.除了已经拥有的 SessionMiddleware
外,还应将 django.contrib.auth.middleware.AuthenticationMiddleware
添加到 MIDDLEWARE
设置中.>
I am practicing Django, and when i try to go to http://localhost/admin/ i get the below error, I have checked settings.py and MIDDLEWARE_CLASSES does exist, is there any other reason why i am getting this message.
AttributeError at /admin/
'WSGIRequest' object has no attribute 'user'
Request Method: GET
Request URL: http://localhost/admin/
Django Version: 2.0
Exception Type: AttributeError
Exception Value:
'WSGIRequest' object has no attribute 'user'
Exception Location: /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/contrib/admin/sites.py in has_permission, line 186
Python Executable: /usr/local/bin/python3
Python Version: 3.6.1
Python Path:
['/Users/yasserhussain/learning_site',
'/Library/Frameworks/Python.framework/Versions/3.6/lib/python36.zip',
'/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6',
'/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/lib-dynload',
'/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages']
Server time: Thu, 4 Jan 2018 00:17:34 +0000
content of MIDDLEWARE in settings
MIDDLEWARE = (
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'django.middleware.security.SecurityMiddleware',
)
Django 2.0 has dropped support for old-style middleware classes in MIDDLEWARE_CLASSES
changelog, last item
Upgrading is straightforward if you use only standard middleware, explained in Upgrading pre-Django 1.10-style middleware.
Often just renaming MIDDLEWARE_CLASSES
to MIDDLEWARE
and removing 'django.contrib.auth.middleware.SessionAuthenticationMiddleware'
is enough.
You must also make sure django.contrib.auth
is installed properly. In addition to SessionMiddleware
, which you already have, you should add django.contrib.auth.middleware.AuthenticationMiddleware
to the MIDDLEWARE
setting.
这篇关于Django管理员错误"WSGIRequest"对象没有属性"user"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!