0

データベースを多用する Web アプリケーションの Django を検討しています。まず、基本的なチュートリアルに従って、MySQL データベースを追加し、モデル、ビュー、およびテスト用のフォルダーを作成しました。(古い models.py、tests.py、views.py を削除しました。) 新しいモデルを作成して、データベースと同期できます。

Django 管理インターフェイスを試すことにするまで、すべてが機能しているように見えました。よく説明できないエラーが表示されます。

AttributeError at /admin/
type object 'CommonMiddleware' has no attribute 'is_usable'

何が原因なのかわかりません。これは私のurls.pyです:

urlpatterns = patterns(
'',
url(r'^admin/doc/', include('django.contrib.admindocs.urls')),
# Uncomment the next line to enable the admin:
url(r'^admin/', include(admin.site.urls)),

そして、ここsettings.pyにコメントを取り除いた私の があります:

DEBUG = True
TEMPLATE_DEBUG = DEBUG

ADMINS = (
    ('admin', 'admin@example.com'),
)

MANAGERS = ADMINS

DATABASES = dict(
    default=dict(
        ENGINE='django.db.backends.mysql',     
        NAME='mydbname',                   
        USER='root',
        PASSWORD='******',
        HOST='',        
        PORT='8000',    
    )
)

# This is redirected to localhost by C:Windows/System32/drivers/etc/hosts
ALLOWED_HOSTS = ['mysite.com']
TIME_ZONE = 'Europe/Amsterdam'
LANGUAGE_CODE = 'en-us'
SITE_ID = 1
USE_I18N = True
USE_L10N = True
USE_TZ = True
MEDIA_ROOT = ''
MEDIA_URL = ''
STATIC_ROOT = ''
STATIC_URL = '/static/'
STATICFILES_DIRS = (    )
STATICFILES_FINDERS = (
    'django.contrib.staticfiles.finders.FileSystemFinder',
    'django.contrib.staticfiles.finders.AppDirectoriesFinder',
)

SECRET_KEY = '****************************************'

TEMPLATE_LOADERS = (
    'django.template.loaders.filesystem.Loader',
    'django.template.loaders.app_directories.Loader',
    'django.middleware.common.CommonMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
)

ROOT_URLCONF = 'bandage.urls'

WSGI_APPLICATION = 'bandage.wsgi.application'

import os
TEMPLATE_DIRS = (os.path.join(os.path.dirname(__file__), '..', 'templates').replace('\\', '/'),)

INSTALLED_APPS = (
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.sites',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    # Uncomment the next line to enable the admin:
    'django.contrib.admin',
    # Uncomment the next line to enable admin documentation:
    # 'django.contrib.admindocs',
    'application',
)

ご覧のとおり、管理サイトを有効にして URL を見つけましたが、Django ライブラリの一部であるモジュールでエラーが発生しました。完全なトレースは次のとおりです。

Environment:


Request Method: GET
Request URL: http://mysite.com/admin/

Django Version: 1.5.1
Python Version: 2.7.0
Installed Applications:
('django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.sites',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'django.contrib.admin')
Installed Middleware:
('django.middleware.common.CommonMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware')


Traceback:
File "D:\Python27\lib\site-packages\django-1.5.1-py2.7.egg\django\core\handlers\base.py" in get_response
  140.                     response = response.render()
File "D:\Python27\lib\site-packages\django-1.5.1-py2.7.egg\django\template\response.py" in render
  105.             self.content = self.rendered_content
File "D:\Python27\lib\site-packages\django-1.5.1-py2.7.egg\django\template\response.py" in rendered_content
  80.         template = self.resolve_template(self.template_name)
File "D:\Python27\lib\site-packages\django-1.5.1-py2.7.egg\django\template\response.py" in resolve_template
  58.             return loader.get_template(template)
File "D:\Python27\lib\site-packages\django-1.5.1-py2.7.egg\django\template\loader.py" in get_template
  146.     template, origin = find_template(template_name)
File "D:\Python27\lib\site-packages\django-1.5.1-py2.7.egg\django\template\loader.py" in find_template
  129.             loader = find_template_loader(loader_name)
File "D:\Python27\lib\site-packages\django-1.5.1-py2.7.egg\django\template\loader.py" in find_template_loader
  112.         if not func.is_usable:

Exception Type: AttributeError at /admin/
Exception Value: type object 'CommonMiddleware' has no attribute 'is_usable'

どんな助けでも大歓迎です!

4

1 に答える 1

0

にいくつかのミドルウェアがありますTEMPLATE_LOADERS。それらを削除します。

TEMPLATE_LOADERS = (
    'django.template.loaders.filesystem.Loader',
    'django.template.loaders.app_directories.Loader',
)                              #\
                               # | it seems that at some point
                               # | you accidentally removed these
MIDDLEWARE_CLASSES = (         #/
    'django.middleware.common.CommonMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
)
于 2013-04-07T10:35:38.803 に答える