1
votes

This is the error I got and i am not able to get the admin login screen.

AttributeError at /admin/ 'WSGIRequest' object has no attribute 'user' Request Method: GET Request URL: http://127.0.0.1:8000/admin/ Django Version: 2.1.2 Exception Type: AttributeError Exception Value:
'WSGIRequest' object has no attribute 'user' Exception Location: C:\Users\Neptune\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\contrib\admin\sites.py in has_permission, line 186 Python Executable: C:\Users\Neptune\AppData\Local\Programs\Python\Python37-32\python.exe Python Version: 3.7.3 Python Path:
['C:\Users\Neptune\Desktop\MyMusic', 'C:\Users\Neptune\AppData\Local\Programs\Python\Python37-32\python37.zip', 'C:\Users\Neptune\AppData\Local\Programs\Python\Python37-32\DLLs', 'C:\Users\Neptune\AppData\Local\Programs\Python\Python37-32\lib', 'C:\Users\Neptune\AppData\Local\Programs\Python\Python37-32', 'C:\Users\Neptune\AppData\Local\Programs\Python\Python37-32\lib\site-packages', 'C:\Users\Neptune\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django-1.9.1-py3.7.egg'] Server time: Tue, 4 Jun 2019 17:37:30 +0000

1
Maybe there is something wrong in the settings.py, can you post that also in this question - Sammy J
Piggybacking on @SammyJ's comment--the user attribute is normally added to requests by middlewear (specifically django.contrib.auth.middleware.AuthenticationMiddleware), so the MIDDLEWARE of your settings.py would be the first place to look. (See also docs.djangoproject.com/en/2.2/ref/request-response/…) - Jack Brounstein
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', ] @Sammy J this is my setting.py middleware section of code. - Iswarian SG

1 Answers

1
votes

Based on your comment it seems you are doing a mistake in your settings, in Django 2.0 and above the MIDDLEWARE_CLASSES is changed to only MIDDLEWARE so the middleware should be like

MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

link about this in the docs, check this and please be careful, if you are new to django then it is good to learn from the docs, there are many tutorials for django which are too outdated.

You could start from here gettting started page