python - Django 1.8 : ImproperlyConfigured: Module "django.contrib.auth.middleware" does not define a "SessionAuthenticationMiddleware" attribute/class

标签 python django middleware django-middleware django-1.8

我启动了我的 virtualenv。然后通过 python manage.py runserver 启动我的服务器。 我最终访问了我的 Django 站点并收到以下错误。

(venv)N$ python manage.py runserver
Validating models...

0 errors found
June 11, 2015 - 19:27:19
Django version 1.6.5, using settings 'nirsite.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
Traceback (most recent call last):
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/wsgiref/handlers.py", line 85, in run
    self.result = application(self.environ, self.start_response)
  File "/Library/Python/2.7/site-packages/django/contrib/staticfiles/handlers.py", line 67, in __call__
    return self.application(environ, start_response)
  File "/Library/Python/2.7/site-packages/django/core/handlers/wsgi.py", line 187, in __call__
    self.load_middleware()
  File "/Library/Python/2.7/site-packages/django/core/handlers/base.py", line 45, in load_middleware
    mw_class = import_by_path(middleware_path)
  File "/Library/Python/2.7/site-packages/django/utils/module_loading.py", line 31, in import_by_path
    error_prefix, module_path, class_name))
ImproperlyConfigured: Module "django.contrib.auth.middleware" does not define a "SessionAuthenticationMiddleware" attribute/class

我已经检查过这个 Stackoverflow ,我无法用这些答案中的任何一个解决问题。鉴于 venv 设置正确,我认为摆脱任何中间件都没有意义。

我可以根据要求提供更多信息。

更新:

好吧,这看起来像是我的 virtualenv 的问题。 在我启动这个 virtualenv 之后,我在其中执行了 pip install django,但现在如果我再次在其中键入它,我会得到以下内容:

Requirement already satisfied (use --upgrade to upgrade): django in /Library/Python/2.7/site-packages

我认为这不是指向我的 virtualenv,所以我猜这是一个问题。为什么我在的venv没有安装django?我怎样才能解决这个问题?下次不会遇到问题吗?

最佳答案

对于 Django 2.0 及以上

SessionAuthenticationMiddleware 在 Django 2.0 中被移除(参见 Django 2.0 发行说明 here)

只需将其从 MIDDLEWARE_CLASSES 中删除

在这里发布是因为我在升级到 Django 2 时遇到了同样的问题

关于python - Django 1.8 : ImproperlyConfigured: Module "django.contrib.auth.middleware" does not define a "SessionAuthenticationMiddleware" attribute/class,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30790303/

相关文章:

node.js - 添加自定义中间件

python - 使用 numpy 在多个轴上进行 bool 掩码

python - 根据外键选择在 django-admin 中填充值

python - Python中定义类变量时如何引用类方法?

python - 一种在简单界面后转换和组合多种数据类型的模式

django - 模板语法错误 : Caught ImportError while rendering: cannot import name utils

python - 使用 django-subdomains 包的 Django 子域

authorization - MapWhen() 中的 MVC 授权应用于所有 Controller

python - 当所有机器都忙时的标志列?

asp.net-mvc - 与常规 Django 模板相比,NDjango 模板有哪些限制?