Multiple settings.py / requirements.txt

Modeling our new Django project off the excellent Two Scoops of Django book, which recommends breaking up settings and requirements files like so:

├── meetup.pizza           
│ └── meetuppizza
| └── settings/
| └── base.py
| └── local.py
| └── test.py
| └── production.py
| └── requirements/
| └── base.txt
| └── local.txt
| └── test.txt
| └── production.txt

instead of what is generated by default, which looks more like this:

├── meetup.pizza           
│ └── meetuppizza
| └── settings.py
| └── requirements.txt

This more modular configuration allows for more control over what is loaded where with less messy logic (like if statements checking for environment types). Separating our settings and requirements out like this actually solved more problems than it created, as it allowed us to isolate Whitenoise, a Heroku necessity and Travis CI breaker of everything, to the production environment.

Helpful hint: Heroku’s Python buildpack will not recognize your project as a valid without a requirements.txt in the root. This is at odds with our use of a requirements directory, but we got it working with a root requirements.txt that just inherits from requirements/production.txt.

Show your support

Clapping shows how much you appreciated Nicole McCabe’s story.