[Fixed]-Heroku django could not connect to server on db txn

1👍

On heroku your database does not run on localhost, but somewhere in the cloud.

Heroku exposes the postgres connection URL as DATABASE_URL in the environment variables (check heroku config).

You can use the dj_database_url package from kenneth reitz to auto parse it to django settings:

import dj_database_url

DATABASES = {
    'default': dj_database_url.config()
}

https://github.com/kennethreitz/dj-database-url

Leave a comment