【发布时间】:2014-09-16 23:02:45
【问题描述】:
我正在运行一个 virtualenv 来尝试学习 Django,但无论出于何种原因,在安装 Django 之后,当我尝试访问默认的 Django 起始页时,我在浏览器中收到以下错误:
发生服务器错误。请联系管理员。
在我运行服务器的终端窗口中显示以下错误:
配置不当:模块“django.contrib.auth.middleware”未定义“SessionAuthenticationMiddleware”属性/类
如果有人对我在 virtualenv 中出现此错误的原因有任何见解,我将不胜感激。不过,我可以让服务器在非虚拟环境设置中正确运行。
这是完整的堆栈跟踪:
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 "/Users/jruecke/Python/JSON/lib/python2.7/site-packages/Django-1.6.5-py2.7.egg/django/core/handlers/wsgi.py", line 187, in __call__
self.load_middleware()
File "/Users/jruecke/Python/JSON/lib/python2.7/site-packages/Django-1.6.5-py2.7.egg/django/core/handlers/base.py", line 45, in load_middleware
mw_class = import_by_path(middleware_path)
File "/Users/jruecke/Python/JSON/lib/python2.7/site-packages/Django-1.6.5-py2.7.egg/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
[16/Sep/2014 22:44:30] "GET / HTTP/1.1" 500 59
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 "/Users/jruecke/Python/JSON/lib/python2.7/site-packages/Django-1.6.5-py2.7.egg/django/core/handlers/wsgi.py", line 187, in __call__
self.load_middleware()
File "/Users/jruecke/Python/JSON/lib/python2.7/site-packages/Django-1.6.5-py2.7.egg/django/core/handlers/base.py", line 45, in load_middleware
mw_class = import_by_path(middleware_path)
File "/Users/jruecke/Python/JSON/lib/python2.7/site-packages/Django-1.6.5-py2.7.egg/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
【问题讨论】:
-
错误消息说它需要在
MIDDLEWARE_CLASSES设置中输入SessionAuthenticationMiddleware。你试过添加它吗? -
因为我在没有使用 virtualenv 的情况下做了完全相同的事情,所以我不知道我需要添加任何东西。我以前从来没有遇到过这个错误。我要输入什么条目?
-
查看错误的路径,它指向django 1.6.5。 SessionAuthenticationMiddleware 是 django 1.7 中的新功能
-
自 1.10 起已弃用 - docs.djangoproject.com/en/dev/internals/deprecation
标签: python django virtualenv