I have 3 settings files:
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?
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.
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.
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.
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.
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',
)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With