Sixth Edition · Updated to Django 6.0

Django 6
By Example

Sixth Edition · Updated to Django 6.0

Django 6
By Example

Build powerful and reliable Python web applications from scratch.

Other Amazon stores
6thedition
19chapters
940+pages
5projects

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.

New chapter

Testing with pytest

Build a test suite for your e-learning platform with pytest and pytest-django, using reusable fixtures, parametrization, and markers.

New chapter

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.

Django 6

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.

Django 6

Background tasks

Understand the new django.tasks framework and how it relates to running asynchronous tasks with Celery and RabbitMQ.

New content

Accessibility

Make your form fields and authentication system accessible, and test accessibility across languages using screen readers.

Updated

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 3

Models, 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 7

User 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 11

A 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 19

A 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 17

A 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

Diagram of an order being placed and processed by a Celery worker
Visual

Learn with practical diagrams

The hands-on approach is supported by diagrams that guide your projects and make complex Django concepts quick to understand.

URL patterns leading to a view, step by step
Progressive

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

readers online now

About the author and contributors

Antonio Melé

Antonio Melé

Author

Founder and CTO of Orbio AI, an agentic AI platform for HR teams. He previously founded Nucoro, a fintech platform acquired by Backbase in 2023. Antonio has been developing Django projects since 2006.

   

Sarah Abderemane

Sarah Abderemane

Contributor

Software engineer in France championing accessibility through her company, Sarally. She co-founded Djangonaut Space, organizes the Django Paris meetup, and was Vice President of the Django Software Foundation Board in 2025.

   

Juliana Nicacio

Juliana Nicacio

Contributor

Python and Django developer who builds well-tested, maintainable APIs and backend systems. She came to software from wildlife conservation, was nominated as an Individual Member of the Django Software Foundation, and contributes code to Django.

 

Technical reviewers

Editions in other languages

Django 5. Praktyczne tworzenie aplikacji sieciowych. Wydanie IV

Django 5. Praktyczne tworzenie aplikacji sieciowych

ISBN: 9788328918832
Django 5 в примерах

Django 5 в примерах

ISBN: 9785937002594
Django 4项目实例精解

Django 4项目实例精解

ISBN: 9787302647904
예제로 배우는 Django 4

예제로 배우는 Django 4

ISBN: 9788931474435
Aprenda Django 3 com exemplos

Aprenda Django 3 com exemplos

ISBN: 9786586057232
Django 3 kroz primere, prevod III izdanja

Django 3 kroz primere, prevod III izdanja

ISBN: 9788673105529
Django 2

Django 2 en Español

ISBN: 9788426727480

Get your copy

Django 6 By Example is available in print and eBook.