Forums

Django AttributeError at /admin/

Hi, I'm getting an Attribute error: 'WSGIRequest' object has no attribute 'user' and I do not know what caused it or what happened. Does anyone know why?

thanks

There seems to be quite a lot of activity out there on SO and other sites -- do any of these help? https://www.google.com/search?q=WSGIRequest%27+object+has+no+attribute+%27user%27

Hi Harry,

All of the questions there seemed to deal with middleware, so I checked my middleware with https://docs.djangoproject.com/en/1.9/ref/middleware It all looked correct.

Heres my middleware:

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',

]

thought on the error page its says that only two of them are installed:

Request Method: GET
Request URL: http://linuss1.pythonanywhere.com/admin/

Django Version: 1.9.3
Python Version: 3.5.1
Installed Applications:
['django.contrib.admin',
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'keyPads']
>>Installed Middleware:
['django.middleware.common.CommonMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware']

I would try taking out the middlewares to see if you can get to a usable/non-erroring state, and then slowly adding them back in/fiddling with the ordering of the middleware.

hi conrad, I commented all the middleware out yet when I still go to the admin page I get: the error( no surprises there), but It shows that its loading the 'django.middleware.common.CommonMiddleware',and the 'django.middleware.csrf.CsrfViewMiddleware'. I have reloaded the site a lot but I still get the same error of loading the same middleware.

Just to take a different approach -- can you double check that you're using the right version of django? If you're using a virtualenv, just make sure it has the right django versions installed, and that it's configured correctly on the web tab? You might also try uninstalling and reinstalling django in the virtualenv?

It all works now! I overlooked that I had to connect virtualenv to the django project, then I uncommended the middleware and everything was good!

thanks

hooray! :-D