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. You do not need experience with HTML, the command line, or databases either. Each is introduced when the book first needs it, starting with HTML in Chapter 3 and the terminal in Chapter 4.
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 pre-release chapters are labelled as pre-release. 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, so the book names the exact versions it uses. Chapter 4 fixes the Python version and the uv tool; the exact Django release in the 6.1 series is fixed when the project is created. Chapter 14 adds Node.js and npm, pinned the same way, to build the stylesheet. Every code example runs 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. Named topics within each part teach ideas through the Otahque example. References name the chapter, part, and topic so you can find them in the contents.
- Six parts. Each chapter follows the same cycle, in the same order: Why This Matters opens with the problem, framed through Otahque; What You Need to Know explains concepts with read-only examples before project changes; How We Build It is the hands-on part, with the manual approach first and the structured approach second; coding chapters then use Django’s tools; Verify Your Work proves the result with a checklist; Checkpoint: Quiz and Challenge closes with a quiz, a mini-challenge, a summary, and the Git commit; and Test Your Knowledge asks five interview questions. Every chapter follows this cycle; design and requirements chapters build documents rather than code in How We Build It.
- Callouts. Coloured boxes mark six kinds of aside. New Tool and New Concept (purple and green) introduce something by asking what problem exists, what people did before, what it is, and why we chose it. Under the Hood (blue) explains what Django does internally. Common Error (red) shows a mistake before you make it, with the fix. Prefer X? (indigo) acknowledges a reasonable alternative. In practice (amber) connects an idea to a real project.
- 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.
- In practice. A short project connection beside the concept it uses. Each segment names a situation, explains the application of the idea, and gives a consideration to keep in mind. These illustrative scenarios are not claims that a feature has been built; later capabilities stay in their planned chapters.
- 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. On the website, each answer stays folded until you select Show answer.
- 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.
- Interview questions. Five questions at the end of each chapter, from L1 (junior) to L5 (lead). Each answer states what an interviewer is testing, gives a model answer, and lists common mistakes and follow-up questions. L4 and L5 look ahead to design and leadership decisions: attempt them, and return to them in later chapters.
- 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 and 2, you need something to write with. Chapter 3 also uses a desktop browser and an internet connection to observe page requests; it requires no software installation. From Chapter 4, you need a computer on which you can install software, a plain-text code editor, and internet access for the first downloads. Chapter 4, How We Build It, Step 1 lists the exact tool versions and setup steps.
Code and checkpoints
From Chapter 4 onward, every practical step shows the file to edit, the command to run, the output to expect, and what to do if something goes wrong. Once the Django project exists, 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.
A milestone marks a point where something new works (Table F.2). The chapters between milestones build towards the next one. Each chapter page on the website names the milestone it works towards, and the contents mark the chapter where each milestone is reached. A milestone counts as reached only when its checks have run; until then, it is a plan.
| Chapter | Milestone | What works |
|---|---|---|
| 5 | Plan ready | A product brief, written requirements, web vocabulary, a checked Python setup, and a proposed architecture. Django is not installed yet. |
| 6 | First Django page | Your own Django project runs on your computer and shows Django’s welcome page. |
| 9 | First Otahque page | Django answers a request with a page written for Otahque. |
| 14 | Browsable event pages | A styled list of upcoming events, labelled as sample data, with a page for each event and the first automated tests. |
| 34 | First release | One community runs free events. Members sign up, register, see, and cancel their registrations; organizers publish their own events; two people cannot both take the last place. Tests check each product rule. |
| 46 | Event-day operations | Reminders sent in the background, a waitlist that offers released places, and check-in that records each attendance once. |
| 54 | API and integrations | Another program can list published events through an API and receive signed notifications when an event changes. |
| 66 | Deployed application | Otahque runs on a real host over HTTPS, with automated releases, monitoring, rollback, and a rehearsed backup restore. |
| 74 | Optional extensions | Chapters 67–74 support several separate communities, add further community features, and offer an AI assistant whose drafts an organizer reviews before publishing. |
| 75 | Final review | A review of the whole product, with upgrade and maintenance practice. |