Skip to content

Instantly share code, notes, and snippets.

@akheron
Created September 28, 2009 09:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save akheron/195328 to your computer and use it in GitHub Desktop.
Save akheron/195328 to your computer and use it in GitHub Desktop.
Django settings and root urlconf wrapper for loading them outside PYTHONPATH
# Usage:
# Run the server like this (for example):
# DJANGO_SETTINGS_FILE=/path/to/settings.py ./manage runserver --settings=pythonpath.to.settings
# where pythonpath.to is the directory containing this file and is found in PYTHONPATH.
def load_settings():
import os
del globals()['load_settings']
path = os.environ.get('DJANGO_SETTINGS_FILE',
os.path.expanduser('~/.settings.py'))
if not os.path.exists(path):
raise RuntimeError('Django settings file %s not found' % path)
execfile(path, globals())
load_settings()
# Usage:
# In settings.py, set
# ROOT_URLCONF = "pythonpath.to.urls"
# where pythonpath.to is the directory containing this file and is found in PYTHONPATH.
# Then start the server, e.g.:
# DJANGO_ROOT_URLCONF_FILE=/path/to/urls.py ./manage runserver
def load_urls():
import os
del globals()['load_urls']
path = os.environ.get('DJANGO_ROOT_URLCONF_FILE',
os.path.expanduser('~/.urls.py'))
if not os.path.exists(path):
raise RuntimeError('Django root urlconf file %s not found' % path)
execfile(path, globals())
load_urls()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment