Django - ImproperlyConfigured: Module "django.contrib.auth.middleware" Django - ImproperlyConfigured: Module "django.contrib.auth.middleware" django django

Django - ImproperlyConfigured: Module "django.contrib.auth.middleware"


easy solution

just remove

'django.contrib.auth.middleware.SessionAuthenticationMiddleware',

from

MIDDLEWARE_CLASSES = (......)

in your project's settings.py

then, it should work!


I was getting the same error. But i had forgotten to get into my VirtualEnv BEFORE running my server.So make sure that from terminal you first activate virtualenv: source env/bin/activate Then run: python manage.py runserver


As we can see in Django 1.8 release notes

django.contrib.auth.middleware.SessionAuthenticationMiddleware was added in Django 1.7.

And you are using Django-1.6.5 in your virtual environment, hence the does not define error.

Probably you have a newer version of Django installed in your "normal" environment and the server runs correctly. To fix this upgrade Django version inside your virtual environment (prior to updating Django be sure to activate your virtual environment!)

Now to add my two cents to the answers, because everything until now was repetition from ZZY and user1776955

If you run pip install -U Django you will probably bump your version to something higher than 1.10 and then the following will apply:

In Django 1.10, session verification will be enabled regardless of whether or not SessionAuthenticationMiddleware is enabled (at which point SessionAuthenticationMiddleware will have no significance)

Hence it will be safe to delete it and if you update past 2.0 you will HAVE to delete it because Django 2.0 release notes state that:

The SessionAuthenticationMiddleware class is removed. It provided no functionality since session authentication is unconditionally enabled in Django 1.10.

Also a bit unrelated but relevant when updating to this version is that

Support for old-style middleware using settings.MIDDLEWARE_CLASSES is removed

As far as my experience goes it is enough to change MIDDLEWARE_CLASSES to just MIDDLEWARE and delete 'django.contrib.auth.middleware.SessionAuthenticationMiddleware' from the list.