2014-10-01 74 views
3

我正在關注的Django的教程,我馬上遇到了一個問題上的第1部分運行的Python manage.py runserver命令我輸入網址進入我的瀏覽器,並得到一個錯誤後:Django的教程:錯誤的runserver

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 
+0

'Django的tutorial' - 提供一個鏈接,請! – Cullub 2014-10-01 20:22:42

回答

4

它看起來像你正在使用一個版本的Django 1.7之前的版本(1.6.4要具體),和SessionAuthenticationMiddleware沒有出臺,直到Django的1.7。因此,錯誤

Documentation can be found here

在右下方,您可以選擇的Django的版本。選擇適當的版本,然後按照您正在使用的django版本特定的教程進行操作。

+1

嗯,爲什麼它會在那裏,如果我不使用1.7版? – gwf215 2014-10-01 20:27:05

+1

您可能從教程中複製了與django 1.7相關的代碼,這是問題的原因。 – karthikr 2014-10-01 20:27:51

+0

我一直在按照這些說明https://docs.djangoproject.com/en/1.6/intro/tutorial01/當我到達runserver部分是我遇到錯誤的地方。正如原文所示,我正在運行python 2.7.5和django 1.6.4爲什麼要包含SessionAuthenticationMiddleware?您的settings.py中的 – gwf215 2014-10-01 20:41:52

1

只是從你的項目中刪除以下會話認證中間件settings.py

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