mirror of
https://github.com/jazzband/dj-database-url.git
synced 2026-04-24 16:54:44 +00:00
Clarify the usage example in the docs
This commit is contained in:
parent
1937ed9e61
commit
a022bb04a5
1 changed files with 21 additions and 3 deletions
24
README.rst
24
README.rst
|
|
@ -31,20 +31,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
|
||||
|
|
|
|||
Loading…
Reference in a new issue