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.
My original Django version was 1.9 . I ran into the same issue after upgrading to version 2.0.5. Renaming MIDDLEWARE_CLASSES to MIDDLEWARE and removing 'django.contrib.auth.middleware.SessionAuthenticationMiddleware' in settings.py did the job
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With