gpt4 book ai didi

python - 异常值 : 'DatabaseWrapper' object has no attribute 'Database'

转载 作者:行者123 更新时间:2023-11-29 03:36:52 31 4
gpt4 key购买 nike

我在输入这个问题之前查看了类似的帖子。我正在使用 Django 1.5、Python 3.3.2 和 MySQL 5.6/连接器。

我是 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/'

最佳答案

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

关于python - 异常值 : 'DatabaseWrapper' object has no attribute 'Database' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20342619/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com