Multiple django configurations for development and production

Matthew Nuzum —  — 3 Comments

In Rails you automatically get different configurations for development, testing and production. In Django there’s no clear way to do this so here’s how Marc Tardif (a coworker) and I got it working.

Our use case is as follows: We work together on the same programming project but since we’re in different countries (and on different LANs) we have different development configurations. Our production server for the applications we co-develop is yet a different configuration. Furthermore, we use [version control]( to keep track of each others’ work. When I’m not working on a team project I still often run a different configuration on my local pc than I do on the server where I publish my app.

Django’s allows you to pass the parameter –settings=something whenever you use it. This is nice but limiting because most of the configuration is the same for our three configurations. Only a few lines differ (mostly relating to database config).

Therefore there is a stock file where most of the configuration lives. Then for each developer (or each different configuration) there is a settings_[hostname].py file. So for me there is There is also a used for production.

The settings_[hostname].py file gets the customizations needed for me. At the top of this file is the line:

from settings import *

Then I run django like this:

./ –setings_matts-laptop runserver

Here’s a __complete example__:

from settings import *

DATABASE_NAME = ‘/home/matt/Projects/trainingwebsite/database.sqlite’


TIME_ZONE = ‘America/Chicago’

MEDIA_ROOT = ‘/home/matt/Projects/trainingwebsite/media/’
MEDIA_URL = ‘http://localhost/files/’
# Always use forward slashes, even on Windows.
# Don’t forget to use absolute paths, not relative paths.

Your apache mod_python config for production will look something like this:

SetHandler python-program
PythonPath “[‘/srv/site-name/python-packages’] + sys.path”
PythonHandler django.core.handlers.modpython
SetEnv DJANGO_SETTINGS_MODULE trainingwebsite.settings_production

The above assumes your django application lives in the directory /srv/site-name/python-packages/trainingwebsite.

If it helped, please share!Tweet about this on TwitterShare on FacebookShare on LinkedInShare on Google+

Matthew Nuzum

Posts Twitter Facebook

Web guy, big thinker, loves to talk and write. Front end web, mobile and UX developer for John Deere ISG. My projects: @dsmwebgeeks @tekrs @squaretap ✝

3 responses to Multiple django configurations for development and production

  1. Cant believe all I needed was ‘from settings import *’


  2. profile_name = os.environ.get(“SETTINGS_PROFILE”, False)

    if profile_name:
    exec ‘from settings_%s import *’ % (profile_name,)

  3. I’m having some issues with “from settings import *”. Settings are not all correctly imported after the project is deployed.

    I’m wondering if someone ran into that issue too.

Leave a Reply


Text formatting is available via select HTML.

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>