Last active
August 29, 2015 13:56
-
-
Save phpdude/9310482 to your computer and use it in GitHub Desktop.
Django Settings Splitter
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
import inspect | |
import pkgutil | |
import sys | |
ordering = ('env', 'paths') | |
modules = [x[1] for x in pkgutil.walk_packages(__path__)] | |
modules.sort(key=lambda x: x in ordering and ordering.index(x) + 1 or sys.maxint) | |
print 'Loading project.settings submodules: %s' % (", ".join(modules)) | |
for module_name in modules: | |
module = __import__(module_name, globals(), locals(), []) | |
for var_name, val in inspect.getmembers(module): | |
if var_name.isupper(): | |
locals().update({var_name: val}) | |
try: | |
# noinspection PyUnresolvedReferences | |
from ..settings_local import * | |
except ImportError: | |
pass |
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
# Static files (CSS, JavaScript, Images) | |
# https://docs.djangoproject.com/en/1.6/howto/static-files/ | |
import os | |
import sys | |
settings = sys.modules['project.settings'] | |
STATIC_URL = '/static/' | |
STATIC_ROOT = os.path.join(settings.BASE_DIR, 'static') | |
STATICFILES_DIRS = (os.path.join(settings.BASE_DIR, "project/static"),) | |
STATICFILES_FINDERS = ( | |
'django.contrib.staticfiles.finders.FileSystemFinder', | |
'django.contrib.staticfiles.finders.AppDirectoriesFinder', | |
'compressor.finders.CompressorFinder', | |
) |
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
Loading project.settings submodules: env, paths, apps, assets, cache, celery, compressor, crispy, db, emails, facebook, geoip, i18n, logging, middleware, paypal, portal, security, sessions, template, urls, wsgi |
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
import os | |
# Quick-start development settings - unsuitable for production | |
# See https://docs.djangoproject.com/en/1.6/howto/deployment/checklist/ | |
DEBUG = not 'http/mywebsite.com/' in os.path.realpath(__file__) |
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
import sys | |
print 'I WAS LOADED KHA KHA KHA' | |
settings = sys.modules['project.settings'] | |
if settings.DEBUG: | |
print 'In debug mode' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment