Django Tutorial

This Django tutorial helps you learn how to use the Django web framework from scratch via practical and real-world examples.

Prerequisites

You should have the following knowledge to follow the Django tutorial:

The tutorial is relevant to Django 4.x

Section 1. Django Basics

In this section, you’ll learn the basic Django concepts by building a blog that allows users to sign up, sign in and publish blog posts.

Section 2. Django Class-based Views

In this section, you’ll learn the class-based views by building a Todo List App that allows users to register, log in, reset passwords, create profiles, and manage their own tasks.

  • Django Todo App – show you how to create the Todo App project structure from scratch.
  • ListView – learn how to use the ListView class to display a list of tasks.
  • DetailView – show you how to use DetailView class to display a task.
  • CreateView – learn how to use the CreateView class to create a form that creates a task.
  • UpdateView – guide you on how to use the UpdateView class to create a form that edits a task.
  • DeleteView – walk you through the steps of using the DeleteView class to delete an existing task.
  • LoginView – show you how to use LoginView to create a login page for the Todo App.
  • FormView – learn how to use FormView to create a registration page that allows users to sign up.
  • Password Reset – show you how to implement the password reset feature for a Django application.
  • User Profile – walk you through the steps of implementing a user profile feature for the Todo app.

Section 3. Django ORM

In this section, you’ll deep dive into Django ORM and how to use it effectively to interact with relational databases.

  • Django ORM – an introduction to the Django ORM and set up a base project for the next tutorials in this section.
  • One-to-One relationship – explain to you the one-to-one relationship and how to use OneToOne to create a one-to-one relationship in Django.
  • One-to-Many relationship – show you how to use ForeignKey to create a one-to-many relationship in Django.
  • Many-to-Many relationship – learn how to use the ManyToMany to create a many-to-many relationship in Django.
  • Adding extra fields to a many-to-many relationship – show you how to add extra fields to a many-to-many relationship.
  • Limit/Offset – show you how to use slicing to limit the number of objects returned by a QuerySet.
  • Order_by – learn how to use the order_by() method to sort the result returned by a QuerySet. (ORDER BY)
  • Startswith, endswith, and contains – sort data based on pattern matching in Django using the startswith, endswith, and contains (LIKE).
  • In – check if a value is in a list of values (IN).
  • Range – use Django range to check if a value is in a range inclusively (BETWEEN).
  • Isnull – check if a value is NULL or not using isnull and query data accordingly (IS NULL).
  • Exists – return True if a query contains any object or False otherwise.
  • Aggregate – show you how to perform aggregate functions like avg, count, max, min, and sum.
  • Group By – group objects into groups.

Section 4. Building API using Django REST Framework

In this section, you’ll learn step-by-step how to build REST APIs in Django applications.

Section 5. Django Cookies and Sessions

In this section, you’ll learn how cookies work in the browser and how to set and read cookies in Django. Then you explore how to use cookies to support sessions in Django.

  • Cookies – learn about cookies and how to manage them in Django.
  • Sessions – explain how the Django sessions work and how to use them to persist data across requests.