jazzband / dj-database-url

Use Database URLs in your Django Application.
https://pypi.org/project/dj-database-url/
BSD 3-Clause "New" or "Revised" License
1.48k stars 205 forks source link

Support for multiple databases through env variables #99

Closed r3r00t3d closed 6 years ago

r3r00t3d commented 6 years ago

Hi,

just wanted to ask what is the easiest way to interact with multiple databases via env variables? I would like to use DATABASE_URL but I cannot see an easy way to do this.

Thanks.

r4vi commented 6 years ago

hi @r3r00t3d by default it reads from DATABASE_URL if you would like to read from another variable just import os.environ and parse it directly:

import os, dj_database_url

DATABASES['default'] = dj_database_url.parse(os.environ['SOME_OTHER_VARIABLE'], conn_max_age=600)
r3r00t3d commented 6 years ago

Thank you. I appreciate the answer.