Installing Django
If you have already installed Django 4.1, you can skip this section and jump directly to the Creating your first project section.
Django comes as a Python module and thus can be installed in any Python environment. If you haven’t installed Django yet, the following is a quick guide to installing it on your machine.
Installing Django with pip
The pip
package management system is the preferred method of installing Django. Python 3.10 comes with pip
preinstalled, but you can find pip
installation instructions at https://pip.pypa.io/en/stable/installing/.
Run the following command at the shell prompt to install Django with pip
:
pip install Django~=4.1.0
This will install Django’s latest 4.1 version in the Python site-packages/
directory of your virtual environment.
Now we will check whether Django has been successfully installed. Run the following command in a shell prompt:
python -m django --version
If you get the output 4.1.X
, Django has been successfully installed on your machine. If you get the message No module named Django
, Django is not installed on your machine. If you have issues installing Django, you can review the different installation options described in https://docs.djangoproject.com/en/4.1/intro/install/.
Django can be installed in different ways. You can find the different installation options at https://docs.djangoproject.com/en/4.1/topics/install/.
All Python packages used in this chapter are included in the requirements.txt
file in the source code for the chapter. You can follow the instructions to install each Python package in the following sections, or you can install all requirements at once with the command pip install -r requirements.txt
.
New features in Django 4
Django 4 introduces a collection of new features, including some backward-incompatible changes, while deprecating other features and eliminating old functionalities. Being a time-based release, there is no drastic change in Django 4, and it is easy to migrate Django 3 applications to the 4.1 release. While Django 3 included for the first time Asynchronous Server Gateway Interface (ASGI) support, Django 4.0 adds several features such as functional unique constraints for Django models, built-in support for caching data with Redis, a new default timezone implementation using the standard Python package zoneinfo
, a new scrypt
password hasher, template-based rendering for forms, as well as other new minor features. Django 4.0 drops support for Python 3.6 and 3.7. It also drops support for PostgreSQL 9.6, Oracle 12.2, and Oracle 18c. Django 4.1 introduces asynchronous handlers for class-based views, an asynchronous ORM interface, new validation of model constraints and new templates for rendering forms. The 4.1 version drops support for PostgreSQL 10 and MariaDB 10.2.
You can read the complete list of changes in the Django 4.0 release notes at https://docs.djangoproject.com/en/dev/releases/4.0/ and the Django 4.1 release notes at https://docs.djangoproject.com/en/4.1/releases/4.1/.