[Django]-App specific default settings in Django?

4👍

Use django-appconf.

It solves this problem in a nice way, I could quote its README here but that is a bit pointless.

3👍

I wouldn’t mess with INSTALLED_APPS this way as far as I’m concerned. Wrt/ other settings, the canonical solution is to

  • import global settings from you appsettings.py file
  • set values here depending on what’s defined in gobal settings
  • only use appsettings from within your application.

myapp/appsettings.py

from django.conf import settings


ANSWER = getattr(settings, "MYAPP_ANSWER", 42)
SOMETHING_ELSE = getattr(settings, "MYAPP_SOMETHING_ELSE", None)

myapp/models.py

from myapp import appsettings

class Question(object):
    answer = appsettings.ANSWER

2👍

My approach is to have a local_settings.py file which supplements the project’s setting.py.

local_settings.py:

XINSTALLED_APPS = [
    'myproject.app',
    ]

settings.py:

INSTALLED_APPS = [
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    ...
]

try:
    from local_settings import *
except ImportError, exp:
    pass

try:
    INSTALLED_APPS += XINSTALLED_APPS  # defined in local_settings
except NameError:
    pass

1👍

I have done In my last project Like this :

from django.conf import settings

My_APP_ID = getattr(settings, 'My_APP_ID', None)

USER_EMIL_Is = getattr(settings, 'USER_EMIL_Is', Flase)

0👍

you can use django-zero-settings which lets you define your defaults and a setting key for user settings, has auto-import strings, removed settings management, cache, pre-checks, etc.

as an example:

from zero_settings import ZeroSettings

app_settings = ZeroSettings(
    key="APP",
    defaults={
        "INSTALLED_APPS": ["some_app"]
    },
)

and then use it like:

from app.settings import app_settings

print(app_settings.INSTALLED_APPS)

or in your case you can also import it to your settings file and do something like:

from app_settings import app_settings

SECRET_KEY = "secret_key"
# other settings ....
INSTALLED_APPS = [
    *app_settings.INSTALLED_APPS
]

Leave a comment