Django settings.py + dj_database_url on Heroku?

前端 未结 1 386
心在旅途
心在旅途 2021-02-10 17:17

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         


        
相关标签:
1条回答
  • 2021-02-10 17:53

    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

    0 讨论(0)
提交回复
热议问题