Django - ImproperlyConfigured: Module “django.contrib.auth.middleware”

后端 未结 13 735
我寻月下人不归
我寻月下人不归 2020-12-30 19:25

I\'m running a virtualenv to try to learn Django, but for whatever reason after installing Django and when I try to access the default Django start page, I get the following

13条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-30 19:51

    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.

提交回复
热议问题