Created
September 28, 2009 09:58
-
-
Save akheron/195328 to your computer and use it in GitHub Desktop.
Django settings and root urlconf wrapper for loading them outside PYTHONPATH
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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