django 实用工具dj-database-url 快速配置数据库
django快速配置多种数据库
$ pip install dj-database-url
Configure your database in settings.py
from DATABASE_URL
:
import dj_database_url
DATABASES = {
'default': dj_database_url.config(default="postgres:///channels-example", conn_max_age=500)
}
Engine | Django Backend | URL |
---|---|---|
PostgreSQL | django.db.backends.postgresql_psycopg2 | postgres://USER:PASSWORD@HOST:PORT/NAME |
MySQL | django.db.backends.mysql | mysql://USER:PASSWORD@HOST:PORT/NAME?init_command=SET sql_mode=STRICT_TRANS_TABLES |
SQLite | django.db.backends.sqlite3 | sqlite:////full/path/to/your/database/file.sqlite |
... | ... | ... |
夜来风雨声, 代码码多少?