Is this approach to Django with a lot of configuration files reasonable?

Question

Is my approach to multiple Django settings files below reasonable (transparent, secure, etc.)?

My approach

I have settings.pyand a settings_local.py. settings.pyis under version control, but settings_local.pyNOT under version control. In the end, settings.pyhe tries to import settings_local.py, if available.

My theory for this approach is that I can leave my default / safe settings in settings.pyand just click on production to deploy. During the deployment settings_local.pywill not be present, and its local settings will not be used. However, when working, it is locally settings_local.pypresent and its local settings are used.

settings.py

DEBUG = False
MIDDLEWARE_CLASSES = (
    'django.middleware.common.CommonMiddleware',
)
# other settings...

try:
    from settings_local import *
except ImportError:
   pass

settings_local.py

from settings import *

DEBUG = True
MIDDLEWARE_CLASSES += (
    'debug_toolbar.middleware.DebugToolbarMiddleware',
)
# other settings...

, . , , , , .

settings_local.py import settings.py , DRY-, . MIDDLEWARE_CLASSES .

!


, . , , .

, , , , , - , @DrTyrsa @Mark Lavin, !

+4
1

, . . , , (.. ). :

  • settings.py . ( , DEBUG=True, debug_toolbar ..). , " ".
  • settings.py . local_settings.py, . . , .

. , - SplitSettings.

+4
source

All Articles