我正在运行virtualenv尝试学习Django,但是由于安装Django之后的任何原因以及当我尝试访问默认的Django起始页面时,在浏览器中出现以下错误:
发生服务器错误。请与管理员联系。
在我运行服务器的终端窗口中,显示以下错误:
配置不当:模块“ django.contrib.auth.middleware”未定义“ SessionAuthenticationMiddleware”属性/类
如果有人对我为什么在virtualenv中遇到此错误有任何见解,我将不胜感激。不过,我可以使服务器在非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
简单的解决方案
只是删除
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
从
MIDDLEWARE_CLASSES = ( ... ... )
在项目的 settings.py中
然后,它应该工作!