Skip to content

Instantly share code, notes, and snippets.

@SmileyChris
Last active August 29, 2015 13:57
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 SmileyChris/9925185 to your computer and use it in GitHub Desktop.
Save SmileyChris/9925185 to your computer and use it in GitHub Desktop.
AppSettings
from .conf_base import AppSettings
class Settings(AppSettings):
YOUR_SETTING = True
"""
Give each setting some documentation for sphinx autodoc if you like.
"""
settings = Settings()
from django.conf import settings as django_settings
try:
from django.conf import BaseSettings
except ImportError: # Django <= 1.2
from django.conf import Settings as BaseSettings
class AppSettings(BaseSettings):
"""
A holder for app-specific settings.
The holder returns attributes from the project's setting module,
falling back to the default attributes found on a subclass of
``AppSettings`` if the attribute wasn't found.
"""
def __getattribute__(self, attr):
if attr == attr.upper():
try:
return getattr(django_settings, attr)
except AttributeError:
pass
return super(AppSettings, self).__getattribute__(attr)
from yourapp.conf import settings
# You can use normal settings.
settings.INSTALLED_APPS
# You can rely that your custom setting will have the default you gave it in your conf.
settings.YOUR_SETTING
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment