Skip to content

Preparing for Production

Production environments are not like your laptop.

A production-ready Flask app typically needs:

diagram what changes between the dev server and production mermaid
flask run is a single-process development server with the reloader and debugger attached. In production the app is served by a WSGI server running several workers, usually behind a reverse proxy that terminates TLS and serves static files. The debugger must be off -- it executes arbitrary code by design.
  • Debug mode disabled
  • Secrets stored in environment variables
  • A production WSGI server (Gunicorn) instead of flask run
  • Proper logging
  • HTTPS termination (usually via Nginx or platform)
  • Error handling (friendly pages or JSON)
  • Database migrations
  • Static file handling

Running:

  • flask run

on a production server.

Use Gunicorn (or another WSGI server) instead.

Your app should be configured by:

  • environment variables

Not by editing code per environment.

Many deployments benefit from:

  • /health endpoint returning 200

So monitoring systems can detect downtime.

Have some plan for:

  • request logs
  • error logs
  • basic metrics

Even a simple setup is better than none.

pch.coffeeTagline

pch.coffeeCta

pch.feedbackHeading

pch.feedbackSubheading