Django sharing installed applications between Development vs Production

I have 3 settings files:

  • base.py (general)
  • development.py
  • production.py

base.py has:

INSTALLED_APPS = (

    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes'
    ...

but I have some applications that I only needed my development environment, for example debug-toolbar.

I tried this in development.py:

INSTALLED_APPS += (
    'debug_toolbar',
)

But we get the error: NameError: name 'INSTALLED_APPS' is not defined

Settings files are connected as follows:

__init__.py

from .base import *

try:
    from .production import *
except:
    from .development import *

How can I distinguish installed applications between my development / development environment?

+4
source share
2 answers

I myself dealt with this problem, I hacked it like this:

base.py (mine was settings.py)

INSTALLED_APPS = (
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes'
    ... )


# rest of settings.py variables ...

def _add_installed_app(app_name):
    global INSTALLED_APPS

    installed_apps = list(INSTALLED_APPS)
    installed_apps.append(app_name)
    INSTALLED_APPS = tuple(installed_apps)

ADD_INSTALLED_APP = _add_installed_app

development.py ( settings_debug.py)

from base import *

ADD_INSTALLED_APP('debug_toolbar')

production.py

from base import *
+3

DEBUG settings.py ( , DEBUG == FALSE) :

# settings.py
if DEBUG:
    INSTALLED_APPS += (
        # Dev extensions
        'django_extensions',
        'debug_toolbar',
    )
0

All Articles