How do you deal with settings changes that manipulate Python for different environments? That’s a question that came up as I was doing my Django Twitch stream (shameless plug ) tonight.
In my current project configuration, I have multiple settings files for different environments like
settings/production.py, and so on which inherit settings from a
settings/base.py file. I’m trying to switch to a scheme that only uses a single settings file and reads stuff externally. I happened to select goodconf, but you can totally do something similar with django-environ.
My trouble with this switch is that I don’t know what to do when one of my other settings files manipulated Python. For instance, here is
from settings.base import * # noqa INTERNAL_IPS = ("127.0.0.1",) INSTALLED_APPS += ("debug_toolbar",) # noqa MIDDLEWARE.insert(0, "debug_toolbar.middleware.DebugToolbarMiddleware") # noqa
The only substantial change that this settings file is doing is configuring django-debug-toolbar. To do that, I’m monkeying with
MIDDLEWARE at the Python level (i.e., manipulating lists).
If you use a tool like django-environ, how do you like to deal with these environment-specific customizations? It looks like django-configurations might support this with setup methods. I’m interested to see other techniques that people use.