Learn Python with Talk Python's 270 hours of courses

Deploying and running Django web apps in 2021

Episode #301, published Thu, Jan 28, 2021, recorded Tue, Jan 19, 2021

Have you been learning Django and now want to get your site online? Not sure the best way to host it or the trade offs between the various options? Maybe you want to make sure your Django site is secure. On this episode, I'm joined by two Django experts Will Vincent and Carlton Gibson to talk about deploying and running Django in production along with recent updates in Django 3.2 and beyond.

Watch this episode on YouTube
Play on YouTube
Watch the live stream version

Episode Deep Dive

Guests Introduction and Background

Will Vincent is an author of multiple Django books, including Django for Professionals and Django for APIs. He serves on the board of the Django Software Foundation, which steers Django’s future and finances. He also co-hosts the Django Chat podcast and runs learndjango.com.

Carlton Gibson is a Django Fellow contracted by the Django Software Foundation to maintain the framework. He helps manage Django’s tickets, releases, and community contributions alongside his colleague. He also co-hosts the Django Chat podcast with Will.

Their combined expertise in Django, from day-to-day framework maintenance to in-depth instructional writing, offers a unique perspective on deploying and scaling Django web applications.


What to Know If You're New to Python

Here are a few essentials before diving into the deeper points of Django deployment:

  • Understand the basics of virtual environments and package management (e.g., pip install, venv).
  • Recognize that frameworks such as Django provide much more than simple Python scripts; they offer built-in tools for URL routing, data models, and more.
  • Be prepared to learn about hosting and configuration for live web apps, which involves elements like static files, server configurations (e.g., nginx, gunicorn), and environment variables.

Key Points and Takeaways

  1. Why Deployment Matters for Django Django is a powerful “batteries-included” web framework, but getting your project from local development to a stable, secure production environment can be a big leap. Most of the conversation focuses on bridging this “deployment gap” by discussing servers, scaling, security, and more.
  2. Long-Term Support (LTS) and Django’s Release Cycle Django issues major releases roughly every eight months, with certain versions tagged as “LTS” that receive extended support. This structure helps teams choose between quickly adopting new features or staying on a stable version without frequent upgrades.
  3. Django’s Move toward Async With Python’s async and await gaining traction, Django introduced partial async support starting in 3.0, building out async views in 3.1, and continuing into 3.2 and beyond. True async ORM interactions are on the horizon, letting you process I/O-bound tasks more efficiently while still relying on Django’s stable core.
  4. Choosing a Hosting Strategy: PaaS vs. Self-Managed Servers Options for Django hosting range from platform-as-a-service solutions like Heroku to fully self-managed virtual machines and container orchestrations such as Kubernetes. Beginners might prefer Heroku’s simplicity, while advanced teams may opt for AWS or a dedicated VPS for greater customization and control.
  5. Monolith vs. Microservices Larger organizations often discuss splitting applications into microservices. However, Django’s monolithic architecture can scale well up to high-traffic scenarios before microservices or advanced container approaches are genuinely necessary. Sometimes a more capable single machine and a straightforward database are faster to manage than a distributed system.
    • Links and Tools:
      • Nginx (web server / reverse proxy)
      • Gunicorn (WSGI server)
      • uWSGI (alternative WSGI server)
  6. Static Files and the collectstatic Step Django separates your database-driven application from static assets (CSS, images, JavaScript). Deployments typically run a collectstatic command, then serve those files directly via a web server or a CDN. Ignoring this step in production is a common beginner stumbling block.
    • Links and Tools:
      • WhiteNoise (serves static files directly in production)
      • Cloudflare (CDN for accelerating static assets)
  7. SQLite vs. Production Databases While SQLite is handy for local tests and simple sites, production deployments often need a more robust option, such as PostgreSQL. Still, if your use case is read-heavy or has minimal writes, you can stay on SQLite longer than many people realize.
  8. Monitoring and Observability Tools like Sentry and Datadog help diagnose downtime or exceptions that appear only after real users hit your site. Setting up external uptime checks (e.g., “Is the site reachable?”) ensures you’re alerted if the application isn’t accessible to the world, even if it “looks fine” on the server itself.
  9. Leveraging Python Type Hints in Django Python’s type hinting and static analysis tools (like Mypy and Pyright) are changing how Django applications are documented and verified, though Django’s highly dynamic design complicates “inline” hints. Projects like “Django Stubs” offer external stub files for better code completion and fewer runtime errors.
  10. Scaling: Vertical First, Horizontal Later A universal theme is that most Django apps benefit from “vertical scaling” (upgrading your single server specs) before adopting multi-server or microservices. Throwing more hardware at the problem is often cheaper and simpler than adding new layers of complexity, at least initially.

Interesting Quotes and Stories

On “fancy” architectural decisions: “Yes, you can break everything up into microservices, but do you really need them? Sometimes a bigger database server is all you need before that complexity.”

On discovering unexpected errors in production: “I integrated Sentry and all of a sudden, I got these error emails I never knew were happening. It’s pure gold for tracking down real-world issues.”


Key Definitions and Terms

  • WSGI (Web Server Gateway Interface): The original API standard for communication between web servers and Python web applications.
  • ASGI (Asynchronous Server Gateway Interface): A newer standard adding async support to Python web frameworks, enabling concurrency-friendly features.
  • Platform-as-a-Service (PaaS): Hosting solutions where you simply push your app’s code and the service handles server, scaling, and environment setup.
  • collectstatic: A Django management command used to gather static files in one location for production serving.
  • LTS (Long-Term Support): A Django release that receives bug fixes and security patches for an extended period compared to normal releases.

Learning Resources

Below are resources mentioned or related to the show’s topics.


Overall Takeaway

Successfully deploying and running a Django application involves both technical know-how and the ability to evaluate trade-offs between approaches like monolith vs. microservices, platform-as-a-service vs. VPS hosting, and lightweight databases vs. fully managed services. From the show, Will Vincent and Carlton Gibson emphasize that incremental scaling and a solid understanding of Django’s built-in deployment features—combined with consistent monitoring—make for a smooth and maintainable production environment. While the ecosystem can seem complicated, focusing on the fundamentals (like static files, environment variables, and proper error tracking) will help you confidently launch and maintain your Django site.

Links from the show

Guests
Will Vincent: wsvincent.com
Carlton Gibson: @carltongibson

Watch the live stream: youtube.com

Give me back my monolith: craigkerstiens.com
Carlton’s Button hosting platform: btn.dev
Django Software Foundation: djangoproject.com
Django News newsletter: django-news.com
Deployment Checklist: djangoproject.com
Environs 3rd party package for environment variables: github.com
Django Static Files & Templates: learndjango.com
Learn Django: LearnDjango.com

Configuring uWSGI for Production Deployment @ Bloomberg: techatbloomberg.com
Episode transcripts: talkpython.fm

--- Stay in touch with us ---
Subscribe to Talk Python on YouTube: youtube.com
Talk Python on Bluesky: @talkpython.fm at bsky.app
Talk Python on Mastodon: talkpython
Michael on Bluesky: @mkennedy.codes at bsky.app
Michael on Mastodon: mkennedy

Talk Python's Mastodon Michael Kennedy's Mastodon