Django Settings Using multiple settings


Django default project layout creates a single This is often useful to split it like this:


This enables you to work with different settings according to whether you are in development, production, tests or whatever.

When moving from the default layout to this layout, the original becomes settings/ When every other submodule will "subclass" settings/ by starting with from .base import *. For instance, here is what settings/ may look like:

# -*- coding: utf-8 -*-
from .base import *  # noqa

DEBUG = True
EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'
INTERNAL_IPS = ['', '']

Alternative #1

For django-admin commands to work properly, you will have to set DJANGO_SETTINGS_MODULE environment variable (which defaults to myproject.settings). In development, you will set it to In production, you will set it to If you use a virtualenv, best is to set it in your postactivate script:

export PYTHONPATH="/home/me/django_projects/myproject:$VIRTUAL_ENV/lib/python3.4"

If you want to use a settings module that is not pointed by DJANGO_SETTINGS_MODULE for one time, you can use the --settings option of django-admin:

django-admin test --settings=myproject.settings.tests

Alternative #2

If you want to leave DJANGO_SETTINGS_MODULE at its default configuration (myproject.settings), you can simply tell the settings module which configuration to load by placing the import in your file.

In the above example, the same result could be achieved by having an set to:

from .dev import *