python - "settings.DATABASES is improperly configured"与 django 1.6

标签 python django postgresql

我正在 win7 上使用 pycharm 3 和 python/django 在可移植环境中进行开发。我决定尝试将 postgresql 添加到我的项目(“rob1”)中,该项目位于我的 virtualenv“R1”中,并且我使用了 http://sourceforge.net/projects/pgsqlportable/

我更改了 settings.py 以包括:

DATABASES = {
'default': {
    'ENGINE':'django.db.backends.postgresql_psycopg2',
    'NAME': 'test',
    'USER': 'postgres',
    'PASSWORD': '123',
    'HOST': 'localhost',
    'PORT': '5432',
}
}

从民意调查教程 (https://docs.djangoproject.com/en/dev/intro/tutorial01/) 创建模型作为测试后,我运行 syncdb 并得到:

Traceback (most recent call last):
  File "F:\PyCharm 3.0.1\helpers\pycharm\django_manage.py", line 23, in <module>
    run_module(manage_file, None, '__main__', True)
  File "f:\ppython275\App\Lib\runpy.py", line 176, in run_module
    fname, loader, pkg_name)
  File "f:\ppython275\App\Lib\runpy.py", line 82, in _run_module_code
    mod_name, mod_fname, mod_loader, pkg_name)
  File "f:\ppython275\App\Lib\runpy.py", line 72, in _run_code
    exec code in run_globals
  File "F:\envs\r1\rob1\manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "F:\envs\r1\lib\site-packages\django\core\management\__init__.py", line 399, in execute_from_command_line
    utility.execute()
  File "F:\envs\r1\lib\site-packages\django\core\management\__init__.py", line 392, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "F:\envs\r1\lib\site-packages\django\core\management\base.py", line 242, in run_from_argv
    self.execute(*args, **options.__dict__)
  File "F:\envs\r1\lib\site-packages\django\core\management\base.py", line 285, in execute
    output = self.handle(*args, **options)
  File "F:\envs\r1\lib\site-packages\django\core\management\base.py", line 415, in handle
    return self.handle_noargs(**options)
  File "F:\envs\r1\lib\site-packages\django\core\management\commands\syncdb.py", line 57, in handle_noargs
    cursor = connection.cursor()
  File "F:\envs\r1\lib\site-packages\django\db\backends\__init__.py", line 157, in cursor
    cursor = self.make_debug_cursor(self._cursor())
  File "F:\envs\r1\lib\site-packages\django\db\backends\dummy\base.py", line 15, in complain
    raise ImproperlyConfigured("settings.DATABASES is improperly configured. "
django.core.exceptions.ImproperlyConfigured: settings.DATABASES is improperly configured. Please supply the ENGINE value. Check settings documentation for more details.

运行 manage.py diffsettings 我得到

ALLOWED_HOSTS = ['*']
BASE_DIR = 'F:\\envs\\r1\\rob1\\rob1'  ###
DATABASES = {'default': {'AUTOCOMMIT': True, 'ENGINE': 'django.db.backends.dummy', 'ATOMIC_REQUESTS': False, 'NAME': '', 'TEST_MIRROR': None, 'CONN_MAX_AGE': 0, 'TEST_NAME': None, 'TIME_ZONE': 'UTC', 'TEST_COLLATION': None, 'PORT': '', 'HOST': '', 'USER': '', 'TEST_CHARSET': None, 'PASSWORD': '', 'OPTIONS': {}}}
DEBUG = True
INSTALLED_APPS = ('django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', 'getPost', 'gunicorn')
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 = 'rob1.urls'  ###
SECRET_KEY = '****'
SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')
SETTINGS_MODULE = 'rob1.settings'  ###
STATICFILES_DIRS = ('F:\\envs\\r1\\rob1\\rob1\\static',)
STATIC_ROOT = 'staticfiles'
STATIC_URL = '/static/'
TEMPLATE_DEBUG = True
TIME_ZONE = 'UTC'
USE_L10N = True
USE_TZ = True
WSGI_APPLICATION = 'rob1.wsgi.application'    

Process finished with exit code 0

编辑:上面有更多错误信息,只有一个settings.py文件(在rob1中)

既然你让我开始寻找设置 .py 中有一个额外的区域:

# Parse database configuration from $DATABASE_URL
import dj_database_url
DATABASES['default'] =  dj_database_url.config()

谁能告诉我如何解决这个问题?

最佳答案

如果你正在使用dj_database_url.config(),你还需要设置DATABASE_URL:

DATABASE_URL = "postgres://postgres:123@localhost:5432/test"
#                          ^user    ^pw ^host     ^port ^dbname

关于python - "settings.DATABASES is improperly configured"与 django 1.6,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21127099/

相关文章:

python - 使用 urllib2 从受基本身份验证保护的 Jenkins 服务器获取 URL

python - 转置多级索引 pandas

python - 设置自动滴答间隔

javascript - 在 Django 项目中使用 ChaplinJS

python - Django迁移: only part of the model successfully migrated to sql

linux - 使用 Silverlight 访问在 Linux 下运行的 postgres 数据库?

sql - Rails 在多个表上按列排序

python - 使用 twitterAPI 通过高级搜索提取推特数据

PostgreSQL WHERE IN 子句变体

javascript - 在模板中查找 key 失败