Blog Tags: 

Django for development and production

So you developed a Django web application and now need to deploy it into production, but still need to actively continue development (bugfixes, tweaks, adding and testing new features, etc.)

In your development environment you probably had debugging enabled, performance settings disabled, used SQLite as your database, and other settings that make development easier and faster. 

But in production you need to disable debugging, enable performance, and use a real database such as MySQL or PostgreSQL, etc.

Hopefully, your development environment can simulate your production environment as well, sort of staging, so your final tests prior to deployment provides the smallest delta.

  • Sometimes you need to emulate the full production environment.
  • Sometimes you need to emulate the full development environment.
  • Sometimes a mixture of the two.

This leads to the question, how do you seamlessly manage your development and production settings without adding overhead?

It turns out there is quite a lot of discussion on how to setup Django that supports both a development and production environment, for example:

  • Completely different files (usually you configure the webserver to add the production settings to the python path, and use the default (development) settings when using the dev webserver.
  • By hostname
  • By variable (PRODUCTION = True)

We recently came across this issue when we were ready to deploy the TurnKey Hub into production.

I didn't really like the above mentioned solutions, so this is what I came up with:

  • (full settings for production)
  • (override production for full development)

If the environment variable DEVELOPMENT is set, use settings-dev to override the production settings.

I was toying with the idea to have full control over the settings via the environment, for maximum flexibility, but in the end decided against it, as it added too much complexity with not enough gain.

Our looks something like this:

DEBUG = True


DATABASE_NAME = '/tmp/dev.db'

The (full settings for production) includes the following snippet at the end.
if os.environ.get('DEVELOPMENT', None):
    from settings_dev import *

Add new comment