Python Django教程:运行服务器错误

Python Django教程:运行服务器错误,python,django,macos,Python,Django,Macos,我正在学习django教程,在第1部分中我立即遇到了一个问题。运行python manage.py runserver后,我在浏览器中输入URL,并得到一个错误: ImproperlyConfigured: Module "django.contrib.auth.middleware" does not define a "SessionAuthenticationMiddleware" attribute/class" 下面我将错误与我正在运行的python和django版本一起包括在内。任

我正在学习django教程,在第1部分中我立即遇到了一个问题。运行python manage.py runserver后,我在浏览器中输入URL,并得到一个错误:

ImproperlyConfigured: Module "django.contrib.auth.middleware" does not define a "SessionAuthenticationMiddleware" attribute/class"
下面我将错误与我正在运行的python和django版本一起包括在内。任何帮助都将不胜感激

^C172-29-17-104:mysite [redacted]$ python -V
Python 2.7.5

172-29-17-104:mysite [redacted]$ python -c "import django; print(django.get_version())"
1.6.4

172-29-17-104:mysite [redacted]$ python manage.py runserver

Validating models...

0 errors found
October 01, 2014 - 20:12:56
Django version 1.6.4, using settings 'mysite.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 47, 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
[01/Oct/2014 20:13:44] "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 "/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 47, 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/classpython manage.py runserver

看起来您使用的是1.7版之前的django版本(具体来说是1.6.4版),而直到django 1.7版才引入
SessionAuthenticationMiddleware
。因此出现了错误


在右下角,您可以选择django的版本。选择适当的版本,然后按照您正在使用的django版本的特定教程进行操作。

只需从project settings.py中删除以下会话身份验证中间件即可

    'django.contrib.auth.middleware.SessionAuthenticationMiddleware',

Django教程
-请提供链接!嗯,那么,如果我不使用1.7版,为什么会出现这种情况呢?您可能是从django 1.7相关教程中复制了代码,这就是问题的原因。当我进入runserver部分时,我一直在遵循这些说明,这是我遇到错误的地方。正如最初的帖子所显示的,我正在运行python 2.7.5和django 1.6.4。你知道为什么会包括SessionAuthenticationMiddleware吗?在你的settings.py中,你很可能有一个导致问题的中间件条目。删除该行,或者暂时将其注释掉。是的,这很有效!如果我使用的是django的旧版本,你知道为什么会出现这种情况吗?