且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在 Django 中设置 PostgreSQL 数据库

更新时间:2023-02-24 09:30:08

您需要安装psycopg2 Python 库.

You need to install psycopg2 Python library.

下载http://initd.org/psycopg/,然后安装在Python PATH下

Download http://initd.org/psycopg/, then install it under Python PATH

下载后,轻松解压压缩包:

After downloading, easily extract the tarball and:

$ python setup.py install

或者,如果您愿意,也可以通过 easy_installpip.

Or if you wish, install it by either easy_install or pip.

(我更喜欢使用 pip 而不是 easy_install.)

  • $ easy_install psycopg2
  • $ pip install psycopg2

设置.py

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql',
        'NAME': 'db_name',                      
        'USER': 'db_user',
        'PASSWORD': 'db_user_password',
        'HOST': '',
        'PORT': 'db_port_number',
    }
}

- 其他安装说明可以在 下载页面安装页面.