Skip to content

Instantly share code, notes, and snippets.

@phpdude
Last active Aug 29, 2015
Embed
What would you like to do?
Django Settings Splitter
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
# 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',
)
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
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__)
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