Django / FastAPI

Build Python web backends two ways: FastAPI for typed, async APIs with Pydantic and dependency injection, and Django for full-stack apps with its ORM, migrations, forms and admin, with every example run on Django 6.1 and FastAPI 0.142.

Start course →

What you'll learn

  • Choose between Django and FastAPI for a Python web project and set up either.
  • Build FastAPI endpoints with typed parameters, Pydantic validation, response models, dependencies and error handlers.
  • Model data with the Django ORM, create migrations, and write efficient queries without N+1 problems.
  • Use Django views, URLs, forms, transactions and password hashing correctly.
  • Test both frameworks with their test clients and dependency overrides.
  • Harden and deploy Python web apps with security checks and ASGI/WSGI servers.

Syllabus

Python Web Frameworks

  1. Django and FastAPI at a Glance
  2. A Django Project and App
  3. A First FastAPI App

FastAPI Core Features

  1. Request and Response Models With Pydantic
  2. Dependency Injection With Depends
  3. Async Endpoints
  4. Automatic OpenAPI Documentation

FastAPI in Practice

  1. Error Handling
  2. Testing With Dependency Overrides
  3. Databases With FastAPI

Django Models and Migrations

  1. Defining Models
  2. Creating Migrations
  3. Reading the SQL Behind a Migration
  4. Applying Migrations

Querying With the Django ORM

  1. QuerySets: Filtering and Laziness
  2. Avoiding N+1 Queries
  3. Aggregation, Q Objects and F Expressions

Django Views, Forms and Data Integrity

  1. Views and URLs
  2. Forms and Validation
  3. Transactions and Referential Protection

Testing and Security

  1. Testing Django Apps
  2. Password Hashing
  3. Deployment Security Checks

Deployment and a Checklist

  1. ASGI and WSGI Servers
  2. Performance and Scaling
  3. A Python Web Backend Checklist