Django Settings Using a DATABASE_URL from the environment


In PaaS sites such as Heroku, it is usual to receive the database information as a single URL environment variable, instead of several parameters (host, port, user, password...).

There is a module, dj_database_url which automatically extracts the DATABASE_URL environment variable to a Python dictionary appropriate for injecting the database settings in Django.


import dj_database_url

if os.environ.get('DATABASE_URL'):
    DATABASES['default'] =