1

总新手在这里,对不起

  • Mac OSX 10.8 Python 2.7(随自制软件安装)
    • PostgreSQL 9.4(随自制软件安装)
    • psycopg2 2.5(与 macports 一起安装)
    • Django 1.0.4(通过安装python setup.py install

我正在使用本教程,开始后python manage.py shell我跑了

>>> from django.db import connection
>>> cursor = connection.cursor()

并得到以下信息:

Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/db/backends/dummy/base.py", line 15, in complain
    raise ImproperlyConfigured("settings.DATABASES is improperly configured. "
ImproperlyConfigured: settings.DATABASES is improperly configured. Please supply the ENGINE value. Check settings documentation for more details.

我的 settings.py 文件的 DATABASES 部分如下所示:

DATABASE_ENGINE = 'django.db.backends.postgresql_psycopg2'  #postgresql_psycopg2           
DATABASE_NAME = 'mydatabase'                      #mydatabase
DATABASE_USER = 'sarahr6'             # Not used with sqlite3.
DATABASE_PASSWORD = ''         # Not used with sqlite3.
DATABASE_HOST = ''             # Set to empty string for localhost. Not used with sqlite3.
DATABASE_PORT = ''             # Set to empty string for default. Not used with sqlite3.

所以我不明白为什么它说它配置不正确?

4

1 回答 1

1

您需要在以下位置指定DATABASES字典settings.py

包含要与 Django 一起使用的所有数据库的设置的字典。它是一个嵌套字典,其内容将数据库别名映射到包含单个数据库选项的字典。

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql_psycopg2',
        'NAME': 'mydatabase',
        'USER': 'sarahr6',
        'PASSWORD': '',
        'HOST': '',
        'PORT': ''
    }
}
于 2013-08-19T20:52:56.923 回答