Skip to main content
 首页 » 编程设计

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

2025年05月04日18傻小

我启动了我的 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 时遇到了同样的问题