BEFORE YOU BEGIN
Preface, how to use this book, and book structure
Preface
Django from First Principles to Production teaches Django by building one application from an empty folder: Otahque, a place where a community publishes events and people register for them. Instead of learning features in isolation, you meet each idea when the application needs it: when an organizer must publish an event, when two people want the last place, or when the site has to run somewhere other than your own computer.
Why a community events application? The problem is small enough to understand on the first page and rich enough to need most of what a real web application needs: pages, forms, accounts, permissions, a database, tests, security, and deployment. Almost everyone has registered for something; few people have seen what keeps the count correct.
Who this book is for
You do not need to know Django or how the web works. Each term is explained before the book relies on it. You do need basic Python: variables, functions, lists, dictionaries, and simple classes. Chapter 4 includes a readiness check, with exercises and solutions, so you can find and fill any gaps before you write Django code.
If you already build web applications, the requirements, design, and testing chapters may still be useful. The book explains why each piece exists, not only how to write it.
What you will build
Over the book, Otahque grows from a written brief into a working, tested, deployed application. The first release serves one community running free events. Members register individually, check their registration, and cancel; organizers publish and manage their own events. Later chapters add an API, background work, performance and security reviews, deployment, and optional extensions.
About this edition
This edition is a work in progress. Chapters appear one at a time, and draft chapters are labelled as drafts. The people and events in the examples, Sam, Sai, Raj, and Soni and their Python workshop, are fictional. They make ideas concrete; they are not evidence about real communities. Where the book proposes a policy or a number, it says so, and it does not invent measurements.
Software versions change. Before the setup chapter is written, the exact Python and Django versions used in the book will be checked and fixed, and every code example will run from the checkpoint before it.
How to use this book
Read the chapters in order. Each one builds on the decisions, vocabulary, and code of the chapter before it. Within a chapter, read one section at a time and do its exercise before moving on.
What each chapter contains
- Outcomes. Each chapter opens by saying what you will be able to do and what you will produce.
- Sections. Numbered sections, such as 2.3, each teach one idea through the Otahque example.
- Figures and tables. Numbered figures and tables, such as Figure 2.6 or Table 2.1, show a process or bring related facts together. Each caption says what to notice.
- Try it yourself. A short exercise that asks you to apply the idea. Attempt it before reading the answer.
- Questions and answers. Each question, marked Que., is followed immediately by its answer. Cover the answer, decide on yours, then compare.
- Readiness checkpoint. A short self-test. If you cannot do it without looking back, reread the section it draws on.
- Key terms. A table near the end of each chapter that defines the new vocabulary.
- Next. A one-line transition naming what comes next.
Labels and identifiers
Some chapters give requirements short labels, such as BR-1 for a business requirement or PR-2 for a product requirement. A label is a reference, not an explanation: each one appears only after its requirement has been explained in a sentence. The numbers identify entries; they do not show priority.
What you need
For Chapters 1 to 3, you need only something to write with: these chapters establish what we are building and how the web works. From Chapter 4, you will need a computer on which you can install Python and a code editor. Chapter 4 will list exact versions and setup steps; until then, there is nothing to install for this book.
Code and checkpoints
When code begins, every change will show the file to edit, the command to run, the output to expect, and what to do if something goes wrong. Each chapter ends at a checkpoint: a known working state of the project that the next chapter starts from.
Reading on the web and in print
The web and print editions come from the same manuscript. The web edition adds navigation and lets you open each figure at full size; the print edition is laid out for 6 × 9-inch pages. When the two differ, the difference is in layout only.
Book structure
The book has 75 chapters, grouped into ten stages (Figure F.1 and Table F.1). You can stop after Chapter 66 with a complete, deployed application for one community. Chapters 67 to 74 are an advanced, optional continuation.

| Chapters | Stage | What you will be able to do |
|---|---|---|
| 1–8 | Requirements and first project | Describe what Otahque must do, explain how the web works, prepare your Python tools, and create the Django project. |
| 9–14 | Pages and design | Route requests to views, render templates safely, and style pages with Otahque’s design system. |
| 15–23 | Data and the database | Design the first data model, choose the user model, migrate, query records, and manage data in the admin. |
| 24–34 | Accounts and first release | Build forms, publication, accounts, permissions, registration, and cancellation; protect the last place; accept the first release with tests. |
| 35–46 | Growing the application | Refactor with class-based views; add uploads, email, background tasks, progressive enhancement, waitlists, and check-in. |
| 47–54 | APIs and real-time updates | Design and secure an API, integrate external services reliably, and add real-time updates. |
| 55–66 | Performance, security, and deployment | Measure and improve performance, review security, deploy with HTTPS, automate releases, and monitor and recover. |
| 67–72 | Multi-community and extensions | Support several communities safely, then add billing, volunteer planning, team events, and a job board. |
| 73–74 | Optional AI features | Add a bounded AI feature and test its guardrails. Otahque works fully without it. |
| 75 | Final review and maintenance | Review the product, refine the interface, and plan upgrades. |
The contents list every chapter title. A stage is a reading guide, not a fixed promise about every lesson: each chapter’s plan is confirmed before it is written.