This simple Django utility allows you to utilize the 12factor inspired DATABASE_URL environment variable to configure your Django application.
The dj_database_url.config method returns a Django database connection dictionary, populated with all the data specified in your URL. There is also a conn_max_age argument to easily enable Django’s connection pool.
If you’d rather not use an environment variable, you can pass a URL in directly instead to dj_database_url.parse.
Supported Databases
Support currently exists for PostgreSQL, PostGIS, MySQL, MySQL (GIS), Oracle, Oracle (GIS), and SQLite.
Installation
Installation is simple:
$ pip install dj-database-url
Usage
Configure your database in settings.py from DATABASE_URL:
import dj_database_url DATABASES['default'] = dj_database_url.config(conn_max_age=600)
Provide a default:
DATABASES['default'] = dj_database_url.config(default='postgres://...'}
Parse an arbitrary Database URL:
DATABASES['default'] = dj_database_url.parse('postgres://...', conn_max_age=600)
The conn_max_age attribute is the lifetime of a database connection in seconds and is available in Django 1.6+. If you do not set a value, it will default to 0 which is Django’s historical behavior of using a new database connection on each request. Use None for unlimited persistent connections.
Metadata
Release files for dj-database-url 0.4.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| dj-database-url-0.4.1.tar.gz | 4.1 kB | Details |
Release files / dj-database-url-0.4.1.tar.gz
| Download URL | dj-database-url-0.4.1.tar.gz |
|---|---|
| Size | 4.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
7f4c78d2a090df8dfaf56d5d3ff7bbee17360436e4879558317e2314424864cd
|
|
BLAKE2b-256 checksum How to use checksums |
399f30f937db9f9e7a4e4e3205682af4c34c65d647ff9850897ddfbbf5dc6178
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |