Merge pull request #130 from ParthS007/docs-improvement

Clarify the usage example in the docs
This commit is contained in:
Matt Seymour 2022-05-24 21:37:49 +01:00 committed by GitHub
commit e589ed03b5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -38,20 +38,38 @@ Installation is simple::
Usage
-----
Configure your database in ``settings.py`` from ``DATABASE_URL``::
1. If ``DATABASES`` is already defined:
- 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::
- Provide a default::
DATABASES['default'] = dj_database_url.config(default='postgres://...')
Parse an arbitrary Database URL::
- Parse an arbitrary Database URL::
DATABASES['default'] = dj_database_url.parse('postgres://...', conn_max_age=600)
2. If ``DATABASES`` is not defined:
- 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