Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python Django Basics Model Administration Django's Admin

Exception Value: 'WSGIRequest' object has no attribute 'user'

I'm getting an error when trying to go to my 0.0.0.0:8000/admin site. The error is as follows: Environment:

Request Method: GET Request URL: http://0.0.0.0:8000/admin/

Django Version: 1.9.5 Python Version: 2.7.11 Installed Applications: ['django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', 'courses'] Installed Middleware: ['django.middleware.common.CommonMiddleware', 'django.middleware.csrf.CsrfViewMiddleware']

Traceback:

File "/Users/statensupremacy/anaconda/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response

  1. response = self.process_exception_by_middleware(e, request)

File "/Users/statensupremacy/anaconda/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response

  1. response = wrapped_callback(request, *callback_args, **callback_kwargs)

File "/Users/statensupremacy/anaconda/lib/python2.7/site-packages/django/contrib/admin/sites.py" in wrapper

  1. return self.admin_view(view, cacheable)(*args, **kwargs)

File "/Users/statensupremacy/anaconda/lib/python2.7/site-packages/django/utils/decorators.py" in _wrapped_view

  1. response = view_func(request, *args, **kwargs)

File "/Users/statensupremacy/anaconda/lib/python2.7/site-packages/django/views/decorators/cache.py" in _wrapped_view_func

  1. response = view_func(request, *args, **kwargs)

File "/Users/statensupremacy/anaconda/lib/python2.7/site-packages/django/contrib/admin/sites.py" in inner

  1. if not self.has_permission(request):

File "/Users/statensupremacy/anaconda/lib/python2.7/site-packages/django/contrib/admin/sites.py" in has_permission

  1. return request.user.is_active and request.user.is_staff

Exception Type: AttributeError at /admin/ Exception Value: 'WSGIRequest' object has no attribute 'user'

4 Answers

I had the same issue. In settings.py, change MIDDLEWARE (under INSTALLED_APPS) to MIDDLEWARE_CLASSES. It worked for me.

__ROLLER__ Angel
__ROLLER__ Angel
25,606 Points

Have you tried installing Python 3.5 or higher? I see your running Python 2.7...

I have the same issue even though i have MIDDLEWARE_CLASSES in settings.py anyone know why?

Nikolay Nogin
Nikolay Nogin
22,154 Points

I have, or had the same issue and I looked through django documentation (I'm using django 2.0 now, python 3). It says that MIDDLEWARE_CLASSES was renamed into MIDDLEWARE. Also if you have SessionAuthenticationMiddleware - you can have an error, just delete it from MIDDLEWARE. And The order of the MIDDLEWARE also important.