Python – How to manage local vs production settings in Django


What is the recommended way of handling settings for local development and the production server? Some of them (like constants, etc) can be changed/accessed in both, but some of them (like paths to static files) need to remain different, and hence should not be overwritten every time the new code is deployed.

Currently, I am adding all constants to But every time I change some constant locally, I have to copy it to the production server and edit the file for production specific changes… 🙁

Edit: looks like there is no standard answer to this question, I've accepted the most popular method.

Best Solution

Two Scoops of Django: Best Practices for Django 1.5 suggests using version control for your settings files and storing the files in a separate directory:


The file contains common settings (such as MEDIA_ROOT or ADMIN), while and have site-specific settings:

In the base file settings/

    # common apps...

In the local development settings file settings/

from project.settings.base import *

DEBUG = True
    'debug_toolbar', # and other apps for local development

In the file production settings file settings/

from project.settings.base import *

DEBUG = False
    # other apps for production site

Then when you run django, you add the --settings option:

# Running django for local development
$ ./ runserver 0:8000 --settings=project.settings.local

# Running django shell on the production site
$ ./ shell --settings=project.settings.production

The authors of the book have also put up a sample project layout template on Github.