Django Multiple Settings Structure

In my Django projects, I tend to break out into multiple files. This keeps settings for different environments separate from each other. You might want to have debug settings for development environments only. Example settings structure:

(cormier) [[email protected] cormier]$ ls cormier/settings/
(cormier) [[email protected] cormier]

At the top of settings files import base settings.

from .base import *

The settings can be used in two ways, from the command line using –settings parameter.

python manage runserver --settings=cormier.settings.development

or using the environment variable DJANGO_SETTINGS_MODULE.

export DJANGO_SETTINGS_MODULE=cormier.settings.development

If you are experiencing an error message similar to the following:

ImportError: No module named settings.development

Note when you create the settings directory, add an empty file or Python will fail to recognize it as a module.

Happy coding!

Oct 12th, 2017 • Posted in Django, Python
No comments yet.

Leave a comment

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>