How to Check Django Version
- Check Django Version
-
Check Django Version Using the
python
Command -
Check Django Version Using the
django-admin
Command -
Check Django Version Using the
manage.py
File
In this article, we will discuss how to check the version of the Django library.
Before we proceed, here are two key points to make a note of.
- Ensure that Python and Django library is installed on your machine or if you’re using a virtual environment, then don’t forget to switch to it. Otherwise, Python would throw an error that Django doesn’t exist.
- All the outputs will have
X
in place of numbers because the version can be different for everyone.
Check Django Version
Checking Django library’s version using Python is an effortless task. Interestingly, there are four ways in which we can proceed. In all the methods, we will use some functions from the Django library.
Refer to the following code snippet.
import django
from django.utils import version
print(django.VERSION)
print(django.get_version())
print(version.get_complete_version())
print(version.get_version())
Output:
(X, X, X, 'final', X)
'X.X'
(X, X, X, 'final', X)
'X.X'
The VERSION
attribute of Django and the other three functions, namely get_version()
, utils.version.get_complete_version()
, and utils.version.get_version()
can be used to check the version of Django.
Check Django Version Using the python
Command
We can always invoke Python and execute Python code right from the command line using the following syntax.
python [-bBdEhiIOqsSuvVWx?] [-c command | -m module-name | script | - ] [args]
This command has a few options, but we will only use two options to check the Django library version.
Using the option -c
or command
, we can execute one or more newline-separated Python statements right from the command line. These statements have to be wrapped around by double quotation marks ""
.
Refer to the following commands. We will execute the Python code in the previous section right from the command line.
python -c "import django; print(django.VERSION)"
python -c "import django; print(django.get_version())"
python -c "from django.utils import version print(version.get_complete_version())"
python -c "from django.utils import version print(version.get_version())"
Output:
(X, X, X, 'final', X)
X.X
(X, X, X, 'final', X)
X.X
Using the option -m
or module-name
, we can access a Python module and use its options to check the module’s metadata. --version
is used to check the version of a module.
Refer to the following command.
python -m django --version
Output:
X.X
Check Django Version Using the django-admin
Command
We can use the django-admin
command to print the Django library version as well. We will use the option --version
or version
of this command to check the version of the module.
Refer to the following commands.
django-admin version
django-admin --version
Output:
X.X
X.X
Check Django Version Using the manage.py
File
If you have ever created a Django project, you would know that there always exists a manage.py
file inside the project directory. It is an important file, and it is a recommendation not to mess with this file. Nevertheless, we can always use this file to print the Django library version, just like using it the run the Django server.
Refer to the following command.
python manage.py --version
Output:
X.X