且构网

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

如何在Django中设置PostgreSQL数据库

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

您需要安装 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

下载后,轻松解压缩tarball和:

After downloading, easily extract the tarball and:

$ python setup.py install

或者,如果愿意,可以通过 easy_install

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

(我更喜欢无缘无故地使用pip而不是easy_install.)

  • $ easy_install psycopg2
  • $ pip install psycopg2
  • $ 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',
    }
}


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


- Other installation instructions can be found at download page and install page.