Welcome to Django for Beginners, a gentle introduction to learning web development with Python and Django. This book is appropriate for those new to web development or simply new to Django and looking for a step-by-step tutorial on building modern websites.

We will start from scratch and cover proper installation and setup of Django, Python 3, and virtual environments. Next we’ll build four apps of increasing complexity:

  • a Hello World app
  • a Simple app that uses templates and class-based views
  • a Message Board with a database and the Django admin
  • a robust Blog app with forms and user accounts.

By the end of this short book you’ll have an understanding of how Django works in practice and the background needed to fully take advantage of its extremely robust documentation.

Why Django

Django is the most popular Python-based web framework and for good reason. First released in 2005 and named after the famous guitarist Django Reinhardt, it is flexible enough to quickly build small projects but also robust enough to power some of the largest websites on the internet including Instagram, Bitbucket, and Pinterest.

Django inherited Python’s “batteries-included” approach and includes out-of-the box implementations for many of the most common tasks in web development:

  • user authentication
  • robust admin view
  • security
  • multiple database support
  • and much much more.

It features a large and growing ecosystem of third-party packages and remains under active development, supported by an independent, non-profit, the Django Software Foundation. Best of all, Django is free, open-source, and extremely well-documented.

Prerequisites

Unlike many existing Django tutorials–including the official polls tutorial–this book assumes little Python or web development experience.

However you will have a better experience if you have a basic understanding of HTML, CSS, and Python. It is also worth reviewing how the Internet works and how the Web works.

If you become stuck along the way, first try simply Googling the problem you are having. It’s amazing how often this works and results in a Stack Overflow post with the answer you’re looking for. When this fails, it could be an error in the book so feel free to email the author directly at [email protected] for further assistance.

Book layout

There are many code examples in this book, which are denoted as follows:

# This is Python code
print(Hello, World)

For brevity we will use dots ... to denote existing code that remains unchanged, for example in a function we are updating.

def make_my_website:
    ...
    print("All done!")

We will also use the command line console frequently (starting in Chapter 1: Initial Setup) to execute commands, which will take the form of a $ prefix in traditional Unix style.

$ echo "hello, world"

The result of this particular command is the next line will state:

"hello, world"

We will typically combine a command and its output. The command will always be prefaced by a $ and the output will not. For example, the command and result above will be represented as follows:

$ echo "hello, world"
hello, world

Source Code

Complete source code for all examples can be found on Github in the Django for Beginners repository.

Conclusion

In this chapter we learned about Django’s history and why it’s a popular choice for building modern websites. Next up we’ll learn how to properly set up our computer to install Python 3, Django, and create virtual environments for our projects.

Continue on to Chapter 1: Getting Started.



Sign up for the Django For Beginners newsletter for updates when new chapters are available and special discounts for the print edition of the book.