Learn Django

Update Django Settings

Two Django related settings need to be updated in order to prepare our project to be hosted on Heroku. Follow these steps to update them.

Step 1: Add Heroku DB Settings

In a previous lesson you configured Django's database settings for the development environment. However, in production Heroku will configure and manage the database. This is nice feature of Heroku; you can deploy a production application without having to perform the tedious administrative tasks. To enable this we just need to add a few lines of code to the settings file.

Open settings.py and append the below code to the end of the file.

1
2
3
4
# Parse database configuration from $DATABASE_URL
if ENV_ROLE == 'production':
    import dj_database_url
    DATABASES['default'] =  dj_database_url.config()

Step 2: Configured ALLOWED_HOSTS

Heroku needs to have the ALLOWED_HOSTS setting configured a certain way. Open the /.../crmeasy/crmapp/settings.py file, locate the following setting and update it to read as follows:

1
ALLOWED_HOSTS = ['*']

Step 2: Commit Changes

Execute these commands to commit your changes in Git.

1
2
3
4
5
# add files
(venv)$ git add .

# commit files
(venv)$ git commit -m "added Heroku settings to Django"

Track your progress with a free account