异常值:'DatabaseWrapper'对象没有属性'Database'

时间:2013-12-03 03:59:28

标签: python mysql django

在输入此问题之前,我查看了类似的帖子。我使用的是Django 1.5,Python 3.3.2和MySQL 5.6 / Connector。

我是Django / Python的新手,并通过基础教程学习。我创建了一个MySQL数据库,同步一个非常简单的模型,并启动了基本的Web服务器。 我已经通过基本的shell命令向表中添加了条目,一切正常。

然而,当我登录管理员门户时,它会立即抛出异常。

当我成功登录管理门户时,我在浏览器上看到的回溯是:

Environment:


Request Method: POST
Request URL: http://127.0.0.1:8000/admin/

Django Version: 1.6
Python Version: 3.3.2
Installed Applications:
('django.contrib.admin',
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'webmgr')
Installed Middleware:
('django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.common.CommonMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',
 'django.middleware.clickjacking.XFrameOptionsMiddleware')


Traceback:
File "C:\Python33\lib\site-packages\django\core\handlers\base.py" in get_response
  114.                     response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "C:\Python33\lib\site-packages\django\contrib\admin\sites.py" in wrapper
  215.                 return self.admin_view(view, cacheable)(*args, **kwargs)
File "C:\Python33\lib\site-packages\django\utils\decorators.py" in _wrapped_view
  99.                     response = view_func(request, *args, **kwargs)
File "C:\Python33\lib\site-packages\django\views\decorators\cache.py" in _wrapped_view_func
  52.         response = view_func(request, *args, **kwargs)
File "C:\Python33\lib\site-packages\django\contrib\admin\sites.py" in inner
  197.                 return self.login(request)
File "C:\Python33\lib\site-packages\django\views\decorators\cache.py" in _wrapped_view_func
  52.         response = view_func(request, *args, **kwargs)
File "C:\Python33\lib\site-packages\django\contrib\admin\sites.py" in login
  330.         return login(request, **defaults)
File "C:\Python33\lib\site-packages\django\views\decorators\debug.py" in sensitive_post_parameters_wrapper
  75.             return view(request, *args, **kwargs)
File "C:\Python33\lib\site-packages\django\utils\decorators.py" in _wrapped_view
  99.                     response = view_func(request, *args, **kwargs)
File "C:\Python33\lib\site-packages\django\views\decorators\cache.py" in _wrapped_view_func
  52.         response = view_func(request, *args, **kwargs)
File "C:\Python33\lib\site-packages\django\contrib\auth\views.py" in login
  43.             auth_login(request, form.get_user())
File "C:\Python33\lib\site-packages\django\contrib\auth\__init__.py" in login
  83.         request.session.cycle_key()
File "C:\Python33\lib\site-packages\django\contrib\sessions\backends\base.py" in cycle_key
  277.         self.create()
File "C:\Python33\lib\site-packages\django\contrib\sessions\backends\db.py" in create
  40.                 self.save(must_create=True)
File "C:\Python33\lib\site-packages\django\contrib\sessions\backends\db.py" in save
  63.                 obj.save(force_insert=must_create, using=using)
File "C:\Python33\lib\site-packages\django\db\transaction.py" in __exit__
  298.                             connection.savepoint_commit(sid)
File "C:\Python33\lib\site-packages\django\db\backends\__init__.py" in savepoint_commit
  249.         self._savepoint_commit(sid)
File "C:\Python33\lib\site-packages\django\db\backends\__init__.py" in _savepoint_commit
  203.         self.cursor().execute(self.ops.savepoint_commit_sql(sid))
File "C:\Python33\lib\site-packages\django\db\backends\util.py" in execute
  69.             return super(CursorDebugWrapper, self).execute(sql, params)
File "C:\Python33\lib\site-packages\django\db\backends\util.py" in execute
  53.                 return self.cursor.execute(sql, params)
File "C:\Python33\lib\site-packages\django\db\utils.py" in __exit__
  86.             db_exc_type = getattr(self.wrapper.Database, dj_exc_type.__name__)

Exception Type: AttributeError at /admin/
Exception Value: 'DatabaseWrapper' object has no attribute 'Database'

我的设置文件如下:

# 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/1.6/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = ''

# 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',
    'webmgr',
)

MIDDLEWARE_CLASSES = (
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
)

ROOT_URLCONF = 'gymweb.urls'

WSGI_APPLICATION = 'gymweb.wsgi.application'


# Database
# https://docs.djangoproject.com/en/1.6/ref/settings/#databases

DATABASES = {
    'default': {
        'NAME': 'twntest',
        'ENGINE': 'mysql.connector.django',
        'USER': 'root',
        'PASSWORD': '**********',
        'OPTIONS': {
          'autocommit': True,
        },
    }

}
"""
DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
    }
}
"""
# Internationalization
# https://docs.djangoproject.com/en/1.6/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/1.6/howto/static-files/

STATIC_URL = '/static/'

1 个答案:

答案 0 :(得分:0)

重新安装django。好像你已经在1.4之上安装了django 1.5