'WSGIRequest' object has no attribute 'session' while upgrading from django 1.3 to 1.9 'WSGIRequest' object has no attribute 'session' while upgrading from django 1.3 to 1.9 django django

'WSGIRequest' object has no attribute 'session' while upgrading from django 1.3 to 1.9


MIDDLEWARE is a new setting in 1.10 that will replace the old MIDDLEWARE_CLASSES.

Since you're currently on 1.9, Django doesn't recognize the MIDDLEWARE setting. You should use the MIDDLEWARE_CLASSES setting instead:

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


Django 2.0

You can try this in your settings.py, MIDDLEWARE_CLASSES = [....]:

  • Change MIDDLEWARE_CLASSES=[...] to MIDDLEWARE=[...]

  • Remove SessionAuthenticationMiddleware from the MIDDLEWARE=[...] list.

The MIDDLEWARE_CLASSES setting is deprecated in Django 1.10, andremoved in Django 2.0.

The SessionAuthenticationMiddleware class is removed. It provided nofunctionality since session authentication is unconditionally enabledin Django 1.10.


Check the order of the middleware, if you are trying to access it on some middlewares which are listed above the session middleware, you will get this error.