I needed some rails-like environment settings using Django. This is the quick and easy way to get that done. First, after building your "settings.py" file, create an environment under your project root named "env". Move your settings.py file to this directory, rename it "development.py"
Now, in your root directory, open up a new file named "settings.py" and put this in:
import os import os.path PROJECT_ROOT = os.path.normpath(os.path.dirname(__file__)) local_import = "env/development.py" if os.getenv("DJANGO_ENV") == 'TEST': local_import = "env/test.py" elif os.getenv("DJANGO_ENV") == 'PRODUCTION': local_import = "env/production.py" import_file = open(os.path.join(PROJECT_ROOT, local_import)) exec(import_file)
Bingo! Now you have different versions of settings.py depending upon whether or not you're starting the server in TEST, PRODUCTION, or the default, "development". Create production.py and test.py as needed. You can start the server with:
DJANGO_ENV=TEST ./manage.py runserver
And it will load the correct environment. Using a shell script to run a test server and then a test harness might not be the most elegant thing in the world, but at least it's Un*x, and it makes development less stressy.