16
Web + frameworks / Intermediate

Flask and Django frameworks

How Flask and Django organize Python web applications, where each fits, and the production concerns both frameworks share.

flaskdjangopythonframework

01Choosing a framework

AreaFlaskDjango
StyleSmall core / choose componentsBatteries included
ORMUsually SQLAlchemyBuilt-in Django ORM
AdminBuild/customizeBuilt-in admin
Best fitFocused services, custom architectureContent/business apps needing integrated conventions

02Flask application factory

pythonFactory pattern
from flask import Flask


def create_app():
    app = Flask(__name__)
    app.config.from_mapping(SECRET_KEY='dev-only')

    from .public import bp
    app.register_blueprint(bp)
    return app

03Django model + route idea

pythonDjango model
class Project(models.Model):
    slug = models.SlugField(unique=True)
    name = models.CharField(max_length=180)
    published = models.BooleanField(default=True)

04Shared production concerns

  • Strong secret management.
  • Database migrations.
  • Secure cookies and CSRF protection.
  • Authentication/authorization.
  • Reverse-proxy awareness.
  • Static/media strategy.
  • Tests, dependency audit, logs, health checks, backups, and rollback plans.