Django设置Postgresql

这里假定Postgresql数据库已经装好。

首先安装依赖的包

$ sudo yum install python-devel postgresql-devel

如果使用virtualenv,先source一下virtualenv下的“ . bin/activate”,然后运行

$ pip install psycopg2

修改settings.py文件

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

测试

python manage.py shell
>>> from  django.db import connection
>>> cursor = connection.cursor

如果没有返回任何错误说明数据库连接成功。

转载请以链接形式标明本文地址
本文地址:http://blog.csdn.net/kongxx/article/details/48622673

你可能感兴趣的:(Postgresql,django)