Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Separating Django installed apps between Development vs Production

I have 3 settings files:

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

base.py has:

INSTALLED_APPS = (

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

but I have some apps that I only want in my development environment, for example, debug-toolbar.

I tried this in development.py:

INSTALLED_APPS += (
    'debug_toolbar',
)

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

The settings files are connected like this:

__init__.py

from .base import *

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

How can I differentiate the installed apps between my production/development environment?

like image 666
43Tesseracts Avatar asked Jul 07 '16 18:07

43Tesseracts


People also ask

What's the problem with Django settings?

What’s the problem? Django stores all the settings in a project-wide settings.py file. All is fine until the moment you need different settings for different environments (such as a production environment and a development environment to start with). Your development settings should be different from your production settings.

Should you separate development and production dependencies in Python?

00:00 Let’s discuss separating development and production dependencies for your programs. A common challenge with Python dependency management in the real world is that your development and continuous integration environments need additional dependencies that the production environment doesn’t need.

What does the environment variable Django_settings_Module do?

The DJANGO_SETTINGS_MODULE environment variable controls which settings file Django will load. You therefore create separate configuration files for your respective environments (note that they can of course both import * from a separate, "shared settings" file), and use DJANGO_SETTINGS_MODULE to control which one to use.

How do I load Django settings from a shell script?

You can then use a bootstrap script or a process manager to load the correct settings (by setting the environment), or just run it from your shell before starting Django: export DJANGO_SETTINGS_MODULE=myapp.production_settings. Note that you can run this export at any time from a shell — it does not need to live in your .bashrc or anything.


1 Answers

I simply test for DEBUG in my settings.py (assuming that in production DEBUG == FALSE) and add the apps thus:

# settings.py
if DEBUG:
    INSTALLED_APPS += (
        # Dev extensions
        'django_extensions',
        'debug_toolbar',
    )
like image 85
Raddish IoW Avatar answered Oct 09 '22 11:10

Raddish IoW