Primary image for Django Settings Parity: You're Doing It Wrong

Django Settings Parity: You're Doing It Wrong

A common paradigm in Django is to create different settings files for different environments (local, production, staging, etc.). Everyone has their own opinion on how to set these up (see ours here), that’s not what this post is about. Instead, I’d like to point out the inherent danger in this technique and how to prevent shooting yourself in the foot.

When setting up an environment-specific settings file, each setting should be looked at as an untestable point-of-failure. Have you ever found yourself saying, “…but it worked fine on {staging, my machine, etc.}”? This is a problem of parity and it starts with your settings files. Just because you can change all your settings between environments, it doesn’t mean you should. Use restraint. Make your settings as close as possible between environments and examine every divergence to make sure it is absolutely necessary (inheriting from a common base settings file makes the comparison easy). Here’s a few things that you’ll likely need to change between your environments:

  • database connection details
  • 3rd party API keys

If your settings switches only contain those types values, then pat yourself on the back. If, on the other hand, they vary on things like:

  • installed apps
  • database engines
  • middleware

…you’re asking for trouble. It’s ok to adjust these for local debugging, but they should never hit a dev or staging server.

Aim for parity in your settings and you’ll save yourself some heartache and head-scratching down the road.

Peter Baumgartner

About the author

Peter Baumgartner

Peter is the founder of Lincoln Loop, having built it up from a small freelance operation in 2007 to what it is today. He is constantly learning and is well-versed in many technical disciplines including devops, …