[英]django issue starting server because SessionAuthenticationMiddleware
按照本教程操作時,我一直在嘗試使python 3.2.2和django 1.6.5正常工作。 出於某種原因,我一直遇到此錯誤,但無法在線找到有關發生這種情況的答案。
File "/home/salinn/.pyenv/versions/3.2.2/lib/python3.2/site-packages/django/utils/module_loading.py", line 28, in import_by_path
attr = getattr(module, class_name)
AttributeError: 'module' object has no attribute 'SessionAuthenticationMiddleware'
我嘗試過更改網址,並嘗試使用設置MiddlewareClass,任何正確方向的指針都很棒。
我的settings.py文件是
"""
Django settings for mysite project.
For more information on this file, see
https://docs.djangoproject.com/en/dev/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/dev/ref/settings/
"""
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
import os
BASE_DIR = os.path.dirname(os.path.dirname(__file__))
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/dev/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '9xn60p#gnsg+es+xx@sx3f6b_f#stv!ik27myy+g9e3)mtgx)g'
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
TEMPLATE_DEBUG = True
ALLOWED_HOSTS = []
# Application definition
INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
)
MIDDLEWARE_CLASSES = (
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
)
ROOT_URLCONF = 'mysite.urls'
WSGI_APPLICATION = 'mysite.wsgi.application'
# Database
# https://docs.djangoproject.com/en/dev/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}
# Internationalization
# https://docs.djangoproject.com/en/dev/topics/i18n/
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_L10N = True
USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/dev/howto/static-files/
STATIC_URL = '/static/'
django 1.7中添加了django.contrib.auth.middleware.SessionAuthenticationMiddleware
,並且您正在使用Django 1.6
升級到Django 1.7或將其從MIDDLEWARE_CLASSES
刪除。
您可以通過以下方式檢查Django版本:
首先,檢查在Python控制台中導入了哪個版本的Django:
import django
django.VERSION
其次,檢查django-admin.py
的版本-這是用於生成Django項目等的腳本。在系統外殼中運行以下命令:
django-admin.py --version
版本應匹配。 如果他們不這樣做,您可能會以某種方式安裝兩個單獨的Django(例如,針對Python 2和Python 3)。
附帶一提,許多外部模塊仍與Django 1.7不兼容,因此,如果您要構建實際應用程序,也許暫時堅持使用Django 1.6是一個更好的選擇。 另一方面,如果您只想學習香草Django,我認為您應該從最新版本開始。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.