Setting the 'django_settings_module' value

I’d say you’re half right. You’re correct about the Heroku settings side.

Ideally, you should never have to change those Python files. They read from the OS environment variables so, if you set those environment variables, you should be good to go.

Practically, that means you’d set the DJANGO_SETTINGS_MODULE environment variable in your local shell before you start up a local Django web server. For the sake of discussion, let’s assume you’re using ./manage.py runserver for local development.

On a Linux/macOS terminal, you could do something like:

$ export DJANGO_SETTINGS_MODULE=django_project.settings.development
$ ./manage.py runserver

Since you’re using Heroku, you could also use the Heroku toolbelt to handle this as well. I assume you already have a Procfile for Heroku deployments. The heroku local command can run your Procfile commands on your local environment. If you want that command to use the equivalent of config variables on your local machine, then create a file called .env (notice the leading dot) and add a line like:

DJANGO_SETTINGS_MODULE=django_project.settings.development

The heroku local command will read that file, load the values as configuration variables, and start processes on your machine that match with what’s in your Procfile.

Does that make sense?

1 Like