- Author:
- ElfSternberg
- Posted:
- October 14, 2009
- Language:
- Python
- Version:
- 1.1
- Score:
- 0 (after 2 ratings)
This is a replacement for settings.py, which moves the actual settings files into a directory called "env" and establishes different versions for different settings of the environment variable DJANGO_ENV. At runtime, the specified development environment can be found and loaded into the local context of settings.py, which is then picked up by whatever routine manage.py is kicking off.
1 2 3 4 5 6 7 8 9 10 11 12 13 | 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)
|
More like this
- Template tag - list punctuation for a list of items by shapiromatron 10 months, 1 week ago
- JSONRequestMiddleware adds a .json() method to your HttpRequests by cdcarter 10 months, 2 weeks ago
- Serializer factory with Django Rest Framework by julio 1 year, 5 months ago
- Image compression before saving the new model / work with JPG, PNG by Schleidens 1 year, 6 months ago
- Help text hyperlinks by sa2812 1 year, 6 months ago
Comments
That's cool and see why someone might want to do this; but I find it simpler to duplicate my settings.py file rename it to local_settings.py (or whatever you like) and add the following to the end of the original settings.py:
#
Please login first before commenting.