Build powerful and reliable Python web applications from scratch.
Other Amazon stores
Over the years, this book has become part of Django’s story and of the journey of many people who have started learning the framework.
Paolo Melchiorre, Django Contributor
Who this book is for
Python programmers new to Django
You have basic Python programming knowledge and want to learn Django through hands-on experience.
Developers coming from other frameworks
You are moving to Django from another web framework and want to see how it works by building real projects.
Django developers who want to go further
You have used Django before and want to learn best practices and integrate other technologies to scale your applications.
What you need: a good working knowledge of Python, and to be comfortable with HTML and JavaScript.
New in the sixth edition
Fully updated to Django 6.0, with two new chapters and new content across every project.
Testing with pytest
Build a test suite for your e-learning platform with pytest and pytest-django, using reusable fixtures, parametrization, and markers.
Building an AI agent
Learn how AI agents work (the model, the tools and the loop), then build a shop assistant with Gemini and a chat interface using HTMX and no JavaScript. A bonus digital chapter.
Template partials and HTMX
Define reusable fragments directly within a template and combine them with HTMX to update the shopping cart of your online shop.
Background tasks
Understand the new django.tasks framework and how it relates to running asynchronous tasks with Celery and RabbitMQ.
Accessibility
Make your form fields and authentication system accessible, and test accessibility across languages using screen readers.
Modern Django tooling
All projects are updated for Django 6.0 and cover additions such as installing Django with uv and composite primary keys.
What you will build
Five projects, built from scratch and step by step across 19 chapters.
Blog application
Chapters 1 to 3Models, views, templates and the admin site, then comments, tagging, a sitemap, an RSS feed and a full-text search engine.
PostgreSQLdjango-taggitMarkdown
Image bookmarking website
Chapters 4 to 7User accounts and sign-in with Google, a JavaScript bookmarklet, image thumbnails, infinite scroll, a follower system and an activity stream.
OAuth 2.0JavaScriptRedis
Online shop
Chapters 8 to 11A product catalog, shopping cart and orders, with Stripe payments, PDF invoices, coupons, product recommendations and translations.
CeleryRabbitMQStripeHTMX
E-learning platform
Chapters 12 to 16, 18 and 19A content management system, cached course content, a RESTful API, a test suite, a real-time chat server and a production deployment.
Django REST frameworkMemcachedpytestChannelsDocker
AI chatbot
Chapter 17A shopping assistant for a tea shop: an AI agent that answers customers in plain language, looking up products, prices and stock with the tools you define.
GeminiHTMX
Table of contents
Select a chapter to see what it covers. Chapters 17, 18 and 19 are bonus digital chapters.
01 Building a Blog Application
Create the basic blog models, views, templates and URLs, build QuerySets with the ORM, and configure the administration site.
02 Enhancing Your Blog and Adding Social Features
Add pagination and class-based views, send emails, handle forms and model forms, and build a comment system.
03 Extending Your Blog Application
Add tagging, recommend similar posts, and create custom template tags and filters, a sitemap, an RSS feed and full-text search with PostgreSQL.
04 Building a Social Website
Implement authentication views, user registration and a custom profile model.
05 Implementing Social Authentication
Use the messages framework, build a custom authentication backend, and add sign-in with Google using OAuth 2.0.
06 Sharing Content on Your Website
Create many-to-many relationships, a JavaScript bookmarklet, image thumbnails, asynchronous HTTP requests and infinite scroll pagination.
07 Tracking User Actions
Build a follower system and an activity stream, optimize QuerySets, work with signals, and count image views with Redis.
08 Building an Online Shop
Build a product catalog, a shopping cart using sessions and customer orders, and send asynchronous notifications with Celery and RabbitMQ.
09 Managing Payments and Orders
Integrate Stripe Checkout, export orders to CSV files, add custom views to the administration site, and generate PDF invoices.
10 Extending Your Shop
Create a coupon system and a product recommendation engine with Redis, and update the shopping cart using partials with HTMX.
11 Adding Internationalization to Your Shop
Translate Python code, templates and model fields, add language-specific URLs, and localize form fields.
12 Building an E-Learning Platform
Add fixtures, create the course models, use model inheritance for polymorphic content, and build a custom model field.
13 Creating a Content Management System
Build a CMS with class-based views and mixins, groups and permissions, formsets, and drag-and-drop ordering.
14 Rendering and Caching Content
Build the course catalog and student enrollment, render course contents, and cache them with Memcached and Redis.
15 Building an API
Build a RESTful API with Django REST framework: serializers, viewsets, routers, authentication and permissions.
16 Testing with pytest
Write a test suite with pytest and pytest-django using fixtures, parametrization and markers.
17 Building an AI Agent Bonus
Learn how AI agents work, build a shop assistant with Gemini and your own tools, and create an interactive chat interface with HTMX.
18 Building a Chat Server Bonus
Use Django Channels and WebSockets to build a real-time chat server with chat history.
19 Going Live Bonus
Set up a production environment with PostgreSQL, Redis, uWSGI, NGINX and Daphne using Docker Compose, serve it over HTTPS, and build custom middleware and management commands.
What readers say
Reviews from readers of previous editions
How the book teaches
Learn with practical diagrams
The hands-on approach is supported by diagrams that guide your projects and make complex Django concepts quick to understand.
Build like a pro, step by step
Start with basic functionality and gradually tackle more complex features. Each chapter builds on the previous one, so you develop production-ready code as you go.
Join a community of readers like you
Join the Django by Example community on Discord and introduce yourself