Introducing and installing Django
Django is a high-level Python web framework that encourages rapid development and clean, pragmatic design (https://www.djangoproject.com/). Django makes it easier to build better web apps more quickly and with less code.
There are several ways to install Django; we will use pip
to install Django in this book. pip is the standard package manager for Python to install and manage packages not part of the standard Python library. pip
is automatically installed if you downloaded Python from https://www.python.org/.
First, check whether you have pip
installed by going to the Terminal and running the following commands:
- For macOS, run this:
pip3
- For Windows, run this:
pip
If you have pip
installed, the output should display a list of pip
commands, as shown in Figure 1.3:
Figure 1.3 – Checking whether pip is installed on Windows
Next, to install Django, run the following commands:
- For macOS, run this:
pip3 install django==5.0
- For Windows, run this:
pip install django==5.0
The preceding command will retrieve the Django 5.0 code version and install it on your machine. Note that there may be newer versions available when you’re reading this book. However, we recommend continuing to use Django 5.0 to ensure that the code in this book will function correctly. After installation, close and reopen your Terminal.
To check whether you have installed Django, run the following commands.
- For macOS, run this:
python3 -m django
- For Windows, run this:
python -m django
Now, the output will show you all the Django commands you can use, as shown in Figure 1.4:
Figure 1.4 – The Django module commands on macOS
Over the course of the book, you will progressively be introduced to some of the preceding commands.
Note
It is also common to use virtual environments (such as the venv module) to manage your Python and Django projects and dependencies. For now, we will not use venv to get started quickly on Django. We will learn how to use and configure venv at the end of this book.
We have all the tools we need to create a Django project. Now, let’s move on to doing that.