我正在练习 Django,当我尝试去http://localhost/admin/ http://localhost/admin/我收到以下错误,我已检查 settings.py 并且 MIDDLEWARE_CLASSES 确实存在,是否还有其他原因导致我收到此消息。
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
设置中中间件的内容
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
变更日志,最后一项 https://docs.djangoproject.com/en/2.0/releases/2.0/
如果您仅使用标准中间件,升级就很简单,如升级 Django 1.10 之前版本的中间件 https://docs.djangoproject.com/en/2.0/topics/http/middleware/#upgrading-pre-django-1-10-style-middleware。
通常只是重命名MIDDLEWARE_CLASSES
to MIDDLEWARE
并删除'django.contrib.auth.middleware.SessionAuthenticationMiddleware'
足够。
您还必须确保django.contrib.auth已正确安装 https://docs.djangoproject.com/en/2.0/topics/auth/#installation。此外SessionMiddleware
,你已经有了,你应该添加django.contrib.auth.middleware.AuthenticationMiddleware
to the MIDDLEWARE
环境。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)