Installing Django
Django arrives with one pip command. Pip is the installer that adds Python libraries.
The install command
This command installs Django. Run it in a terminal.
pip install djangoThe version check
This code asks for the installed Django version. The answer starts with 6.
import django
print(django.get_version().split(".")[0])Example
import django
print(django.get_version().split(".")[0])
print("Django is installed")Key points
- Use pip install django to install Django.
- Pip runs at a terminal prompt.
- Pip runs in a terminal, never inside a Python file.
- A terminal takes typed commands and runs them.
- Run a short version check in Python after the install.
- Version numbers carry three parts, like 6.1.3.
In this example, get_version reads the installed Django version. The opening print shows 6, the first part. The closing print names the result: Django is installed.
Note
If the check fails, Django is missing, so install it once more.
Try it Yourself
Edit the code, then press Run.
Running is simulated
Exercise
Which command installs Django?