Seamless Switching Between Live and Development
It’s quite likely your local Django project will have slightly different settings to your live Django project - even if it is only database access details. Here is a simple way of switching with exactly the same codebase in each. (This is really for Linux/Mac OS but can be done on Windows as well)
In you application root (where settings.py currently is) create a folder called settings.
In this new folder create 4 files, __init__.py
, main.py
, dev.py
, live.py
.
Add you current settings.py
content to main.py
and delete the settings.py
file.
Inside __init__.py
add the following
Now create an environment variable that is loaded every time you open the terminal window.
On OS X edit your ~/.bash_profile file, on Linux it is ~/.bashrc - with the following
Now, whenever loading settings, your developement version will load the default and any custom settings you have in your dev.py file. Where using source control, you may want to add this as an exception therefore having specific development config on each of the development machines.