When Django 2 was released, a lot changed in the Django world.
Not just because we finally got rid of the complications with having to deal with both Python 2 and 3, but also because of the many new features, tweaks, updates and optimizations that ensure Django keeps getting better and better. Django 3 continues the tradition of continual improvement in Django’s codebase.
What many of you may not know, is the original Mastering Django:Core was an update of the original book written by two of the creators of Django—Adrian Holovaty and Jacob Kaplan-Moss. Given the original book had been around since Django 1.1, it got dated. There are also a lot of similarities to the Django docs in several chapters.
(FUNNY ASIDE: I have had a couple of people email me and take me to task for copying the docs. Lol! Given that the guys who wrote the original book also wrote the original docs, that will happen folks!)
I have decided to start with a clean sheet of paper for Mastering Django. This means you don’t just get an update; you get a new book, written from scratch to meet the needs of today’s programmers.
First and foremost, the book remains a plain-English, easy to follow deep-dive into Django’s commonly used core functionalities. It covers both Django 2 and Django 3.
Second, the book complements the existing docs; it doesn’t just reproduce them in a different format. I have removed all the original material from Jacob and Adrian’s book and all the content from the Django documentation. There are lots of topics not covered adequately in the docs, which provide ample opportunities for me to create resources that will make you a better Django programmer. I have done my best to include them in this book.
Third, the book takes a more practical approach, with less emphasis on theory and more exploration of working code. It’s impossible to put all Django’s functions into a single book, but I have done my best to include the functions, classes and tools you will use regularly. With each major function or class, I expand them into functioning code examples. Source code is also available for Mastering Django.
And finally, while I will not be releasing the book as open-source, the early chapters will remain free to access and read on djangobook.com. As with the previous book, all income from sales support the Django Book project, allowing me to keep the core content ad-free and accessible to all.
Exciting times ahead! 🙂
All the best with your programming journey!
Who This Book is For
This book is a programmer’s manual targeted at intermediate to advanced programmers wishing to gain an in-depth understanding of Django.
In saying that, it doesn’t mean beginners can’t get value out of the book. Since the publication of the first edition of the book, roughly half of the readers I have spoken to identified as being a beginner when they started out with the book.
The way I write—building on simple concepts and explaining every step—is highly accessible to beginners, so if you are a beginner, you will still learn a great deal about Django from the book.
Where the book can challenge beginners is all the peripheral stuff—HTML, CSS, Python and web development in general—that I don’t explain in any detail. The book is big enough as it is, without me trying to teach you all the stuff you need to know that isn’t Django-related!
I do, however, give you lots of references so you can easily get more information if you need it.
Structure of the Book
I’ve broken the book up into two parts:
- PART 1: Fundamentals—A high-level overview of Django, how it’s structured, and its core components so you can grasp how Django brings together each element to create powerful and scalable web applications.
- PART 2: Essentials—This is the meaty middle of the book where we take a deep and detailed dive into the core modules of Django so you can gain a thorough and practical understanding of all the most commonly used modules in Django.
Throughout the book, I will use snippets of code from a fictitious website for a social or sporting club called MyClub.
It was my original plan for this book to end up with a complete website for MyClub. However, it was apparent halfway through that a book that teaches you as much as possible about the popular parts of Django has very different goals to a book that teaches you how to create a complex, professional website.
In the latter case, no more so than the need to write tests. Tests, while necessary for developing a professional application, distract from learning the core functions of Django. If I wrote proper tests for all the code in this book, I would double the size of the codebase and add little to your learning. For these reasons, I have kept the code in this book to illustrative snippets.
Required Programming Knowledge
The book assumes you have had little to no experience with Django.
I expect you to have a basic understanding of web technologies like HTML and CSS, and a basic understanding of how to structure code. You should also be familiar with your OS’s terminal or shell program. Absolute beginners shouldn’t be too concerned, as it’s easy to learn the basics, and that’s all you need to get value out of the book.
As Django is written in Python, I also assume you have a basic understanding of Python. Although, since Python is so easy to learn and there are such great resources available online for Python, I haven’t heard from a learner yet who said not knowing Python was a barrier. You will learn a lot about Python just by learning Django, and all the extras you need to know are easy to find online.
As the book only covers core Django, you don’t require any special functions or libraries, so the latest versions of Python 3 and Django 2 or 3 are OK. At the time of writing, this is Python 3.8.3 and Django 2.2.12 (for Django 2) and Django 3.0.6 (for Django 3).
I provide installation instructions for Windows and Mac users. Linux users can refer to the 90 million Linux installation tutorials online (OK, so that’s maybe an exaggeration, but there are lots).
All the code in this book will run on Windows, macOS or Linux. While the code and screenshots are all from a Windows machine, the fundamentals remain the same—all three have a terminal or command window and management commands like
runserver work the same on all three platforms.
Coding style is also identical across platforms with one exception—I use Windows-style backslashes in file paths. This is to assist Windows users to differentiate between Windows’ native use of backslashes and Django’s implementation of forward slashes in path names. Linux and macOS users, simply need to substitute forward slashes in these cases.
All browser screenshots are taken from the latest version of the Chrome browser. If you are using FireFox, Safari or some other browser, your screen may look different than the screenshots.
The images are in full-color in the PDF and eBook versions but are grayscale in the printed book (color is way too expensive to print). Paperback users are encouraged to run the code to see the full-color effect in your browser.
You can download the source code and resources in this book from
The included source has been written in Django 3.0. All source code has been tested and will run unmodified on Django 2.2, except for the MariaDB configuration files as MariaDB support was not added until Django 3.0.
The source has been tested against the version of SQLite that comes with Django. While the data structures used in the book are simple and shouldn’t cause problems if you decide to use another database, there are no guarantees. If you find any database-related quirks, refer to the database engine documentation.
The source is broken up into folders, one for each chapter of the book. Rather than delete code that changes from chapter to chapter, I have commented out lines of code in the source so you can see where the code has changed.
Code line numbering in the book is provided so you can easily cross-reference my explanations to individual lines of code in the book. In most cases, line numbering in the book does not match line numbers in the source files.
The source is not designed to be executed as-is. The SQLite database file and migrations for each chapter have been removed from the source. While copying the source code from a chapter and running it inside a virtual environment will work in most cases (after running the migrations), there is no guarantee it will. The source code is for your reference and to assist your learning, it’s not fully functioning code that you can just copy and use in your projects.
Errata and Django 3 Updates
I will be publishing errata (bugs and typos) information and updates for future versions of Django 3 on the website here:
For any other enquiries regarding the book, you can contact me via the help page on the Djangobook website. Note that, due to working full-time, it’s very difficult for me to find time to answer Django questions that don’t directly relate to my books and courses.
Your first points of contact for general information on Django and answers to “how do I…” questions should be Stack Overflow, your favorite search engine, and any one of the dozens of social media groups relating to Django.