MIDDLEWARE vs MIDDLEWARE_CLASSES: 'WSGIRequest' object has no attribute 'user'

593 views
Skip to first unread message

Andrew Emory

unread,
Aug 17, 2016, 6:43:14 PM8/17/16
to Django users
My settings.py file has the default MIDDLEWARE settings generated by django-admin startapp:

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

But when I visit /admin I get an Attribute Error with a traceback that lists 

Installed Middleware:
['django.middleware.common.CommonMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware']

And Request_Information - Settings that lists: 
MIDDLEWARE_CLASSES
['django.middleware.common.CommonMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware']

I am thinking of editing my settings file to read MIDDLEWARE_CLASSES instead of MIDDLEWARE (because of stack-overflow articles) but according to the Django Documentation that will only sweep the problem under the rug rather than addressing the issue.  I don't see why, at this point, I should deviate from the default settings.  Or, what caused the problem in the first place.

Any help would be appreciated.

Tim Graham

unread,
Aug 18, 2016, 8:43:55 AM8/18/16
to Django users
Are you running Django 1.10? It looks like your MIDDLEWARE setting is ignored which suggests you might be using an older version.
Reply all
Reply to author
Forward
0 new messages