Understanding the Need: A Django Deployment Guide

Django is huge and has an answer for almost everything, even if it takes an extremely long time to understand. That is also what makes it great, an answer for everything (also the ability that once you have learned it you can create a robust MVP by the end of the day). We love Django because when writing an application in Flask or Pyramid, you simply end up trying to recreate functions Django already has (even if you didn’t know they existed).

Unfortunately it is my belief that there is little to no modern (circa 2017) documentation on how to deploy a full stack web application using Django. “This is a big claim” many veterans might say, however I have yet to see a fool proof guide explaining from start to finish, every detailed bit of Django and then the caveats of deploying it. You and I see even less posts explaining how to integrate Django with the newest technologies. Questions include how to implement Django with component based Vue.js, or “What is the standard configuration for NGINX in Docker Compose with Django?” Many of the blog posts currently found when searching on Django deployment tend to focus on one user’s specific case, forget key industry standards and technologies, use Python 2.7 (in 2016), and are generally not up to snuff.

To paint a picture, these new users of Django will spend some weeks unraveling its “mysteries” (on their local machines), believing that soon a light at the end of the tunnel will be reached where they simply push to production. Standard learning for new Django users include:

  1. Reading through the official Django documentation, Two Scopes of Django, or Django Girls
  2. Read through the documentation again
  3. Migration errors
  4. Get authentication squared away
  5. Learn about Class Based Views
  6. Use Class Based Views for everything
  7. Want some feature such as email verification, but don’t want to use 3rd party apps i.e. AllAuth, so they attempt to write it by hand
  8. Migration error, this time a merge conflict with another team member for pushing 0001_initial.py
  9. Realize 3rd party apps are acceptable: installs AllAuth as CEO has asked for Facebook and Twitter registration. Email registration is replaced

Several Weeks and Model Refactors Later

  1. Stop using Class Based Views for everything

When a new Django developer finally believes they have a working application and decide to make DEBUG=False, the light at the end of the tunnel instead opens a doorway to the 9 Circles of Deployment Hell.

At this point, assuming they’ve made it, an abyss of questions with no clear answers emerge:

  • What are the best practices for deploying? Allowed Hosts? SITE_ID = 1?
  • How do I manage secret keys without environment variables?
  • What is the best Platform as a Service provider for Django?
  • How to set up PostgreSQL Server?
  • Request Management? Reverse Proxy? Static Files?
  • Media Files? Pillow? Amazon S3?
  • What is Docker? Docker-Compose? Docker-Swarm?
  • Why are my pages loading so slow? What about client side rendering?
  • What about JavaScript Front End Frameworks and REST APIs?
  • <ul>{% for buzzword in other_buzzwords %}<li>{{ buzzword }}</li>{% endfor %}</ul>

It seems that for every question answered, it is simply a door to another set of problems that the user simply had not known of before asking.

Our engineering, facing the Hydra of Django deployment.

Many seasoned Django developers may look at the above and laugh at some of the questions asked, but at one point they too fought with the monster. In reality, a starting Full Stack Engineer or a long-time Backend Engineer who has been tasked with Dev Ops is learning piece by piece. The goal now is to determine what are the best most modern practices for deploying Django web applications. In doing so, we will discover best practices for deploying any web application in general (Ruby on Rails, Node/Express, Spring).

At the time being, my thoughts for the structure of a modern Django deployment guide include:

  • Creating a Django Application by Hand
  • Models setup and advanced model techniques
  • Discussing multiple Settings and Configuration files for local and production environments
  • Creating a REST API using Django REST API
  • Using a front end Javascript library (React or Vue.js) and not the Django Server Side Rendering (not simply adding the Webpack built .js and .css files to a Django severed index.html)
  • Testing Django models, views, API, and JavaScript Front End Technology
  • Handling requests and reverse proxy with NGINX
  • Wrapping Django, Node, Postgres, NGINX, (possibly Redis) into a Docker-Compose file
  • Implementing continuous integration / deployment techniques

I will be reaching out to colleagues to determine a comprehensive problem / solution list, but am more than happy to take suggestions from readers on what to include in a guide.

Thank you for reading,


For updates on Modern Project please check out: