Last active
August 29, 2015 13:57
-
-
Save SmileyChris/9925185 to your computer and use it in GitHub Desktop.
AppSettings
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
from .conf_base import AppSettings | |
class Settings(AppSettings): | |
YOUR_SETTING = True | |
""" | |
Give each setting some documentation for sphinx autodoc if you like. | |
""" | |
settings = Settings() |
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
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) |
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
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