Rails-like environments using Django

 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

  1. Load a local settings file for dev/test environments by menendez 4 years, 10 months ago
  2. Ensure ugettext is available absolutely everywhere by ElfSternberg 3 years, 11 months ago
  3. Load local settings by ofalk 4 years ago
  4. Ensure submitted slugs do not conflict with existing resolvable URLs by ElfSternberg 3 years, 11 months ago
  5. Extend simplejson to understand closures, functors, generators and iterators by ElfSternberg 4 years ago

Comments

insha (on October 14, 2009):

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:

try: 
    from local_settings import * 
except ImportError: 
    pass

#

(Forgotten your password?)