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:
- Python basics
- HTML/CSS. JavaScript knowledge is not required.
- Relational databases (SQLite, MySQL, PostgreSQL, …).
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.
- Getting Started with Django – help you get started with Django by explaining what the Django framework is, how to install the Django package, set up the project, and launch the Django application using the development web server.
- Creating an application – show you how to create a blog application in Django and map the URLs with the views.
- Building Django Templates – learn how to create templates and pass variables from view functions to them.
- Defining Django models – show you how to create a simple Django model.
- Making & Applying Migrations – learn how to make and apply migrations.
- Django Admin page – show you to use the Django admin page.
- Defining Django form – define a ModelForm that creates a new post and saves it into the database.
- Using Flash messages – show you how to create and display flash messages.
- Creating an Edit Form – learn how to create an edit form that updates a post.
- Creating a Delete Form – show you how to create a Delete Form that deletes a post.
- Login/Logout – create a login/logout system for the Django application.
- Creating Registration Form – show you how to create a registration form that allows users to create an account.
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
, andcontains
(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 orFalse
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.
- Building an API using Django – show you how to use pure Django to build an API.
- Introduction to the Django REST Framework (DRF) – learn how to use the DFR to quickly build an API.
- Permissions – guide you on how to set up permissions for the API.
- JWT Authentication – introduce the JSON Web Token and show you how to integrate JWT authentication in DRF.
- Paginations – show you how to set up pagination for datasets returned by API.
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.