Im following the getting started with Django on Heroku - and it shows to set up dj_database_url...
DATABASES = {\'default\': dj_database_url.config(default=\'po
It is correct as-is.
When running on Heroku, there is an environment variable set (DATABASE_URL
) which contains the database URL (a string like postgres://
, but with a long autogenerated username/password/database-name, and the host is on amazonaws usually)
When running locally, DATABASE_URL
is not set, so your default = '...'
database URL is used instead (allows you to run the code locally for development, and deploy to Heroku, without changing any code).
This is based on the "12factor methodology" (the whole document pretty much describes how Heroku is structured)
The dj_database_url.config
just parses the username/password/host/db-name from the URL, and splits it into the dictionary format expected by Django - the code is rather simple, if you are curious