2👍
There seem to be two parts to your problem:
-
How do I support changing which set of variables (as defined in a config file) are used for a given run
-
How can I load these variables such that they are visible to all the modules of my application.
The standard mechanism for doing the 2nd is to put stuff in settings.py.
If you do FOO="bar"
in settings.py, in your module you can do:
from django.conf import settings
if settings.FOO == "bar":
# Do something
As far as how you can support multiple configurations, the first thing I could come up with is to rename your real settings.py to be real_settings.py and then create a series of config1_settings.py, config2_settings.py, config3_settings.py … which look like:
from real_settings.py import *
from path_to_configX.py import *
where configX.py has all the values for whatever variables you want for configuration X.
You would then start django’s built in server via:
manage.py runserver --settings=configX_settings.py
Note that doing this for a production server (where you can’t as easily just pass something on the command line to kick it off) may be a bit trickier, but you’re going to need to provide more use case details for that.