Created
April 27, 2011 22:48
-
-
Save msabramo/945406 to your computer and use it in GitHub Desktop.
How to load (optional) Django apps only if they're present (from http://blog.jupo.org/post/586256417/optional-django-apps)
This file contains hidden or 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
LOAD_OPTIONAL_APPS = True | |
if LOAD_OPTIONAL_APPS: | |
# <copypaste from="http://blog.jupo.org/post/586256417/optional-django-apps"> | |
# Define any settings specific to each of the optional apps. | |
# | |
import sys | |
USE_SOUTH = not (len(sys.argv) > 1 and sys.argv[1] == "test") | |
DEBUG_TOOLBAR_CONFIG = {"INTERCEPT_REDIRECTS": True} | |
# Sequence for each optional app as a dict containing info about the app. | |
OPTIONAL_APPS = ( | |
{"import": "django_extensions", "apps": ("django_extensions",)}, | |
{"import": "debug_toolbar", "apps": ("debug_toolbar",), | |
"middleware": ("debug_toolbar.middleware.DebugToolbarMiddleware",)}, | |
{"import": "south", "apps": ("south",), "condition": USE_SOUTH}, | |
) | |
# Set up each optional app if available. | |
for app in OPTIONAL_APPS: | |
if app.get("condition", True): | |
try: | |
__import__(app["import"]) | |
except ImportError: | |
pass | |
else: | |
INSTALLED_APPS += app.get("apps", ()) | |
MIDDLEWARE_CLASSES += app.get("middleware", ()) | |
TEMPLATE_CONTEXT_PROCESSORS += app.get("context_processors", ()) | |
# | |
# </copypaste> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment