How to check Django version?

Django is one of the most popular framework for creating web applications. Its initial release was back in 2005, and since then, more than 20 stable versions have been released. Having that many versions available to choose from, we often require methods to check our version in Django, either for deployment or dependency compatibility purposes. So how to check the Django version?

Django version can be checked using multiple approaches.

1. Using the django-admin command line (terminal commands)

$ django-admin version
$ python version
$ python -m django version

2. Using django module (Python console commands)

>>> import django
>>> django.VERSION
(4, 0, 3, 'final', 0)
>>> import django
>>> django.get_version()

3. Using pip (terminal commands)

$ pip show django
Name: Django
Version: 4.0.3
Summary: A high-level Python web framework that encourages rapid development and clean, pragmatic design.
Author: Django Software Foundation
License: BSD-3-Clause
Requires: asgiref, backports.zoneinfo, sqlparse
$ pip freeze | grep Django

4. Using pkg_resources module (Python console command)

>>> import pkg_resources
>>> pkg_resources.get_distribution('django').version

We divide approaches of checking Django version by:

  • Python console commands
  • Terminal commands
Django check version console commands.

Python console commands can be used inside our Django code.

Django check version terminal

What method should I use?

There is a big difference between Python console and terminal commands. So firstly, you should narrow your search of methods to one of the provided approaches.

When to use terminal commands?When to use Python console commands?
Use it when output is not required later in the code.Use it when your code depends on the output of the given method.
Use it for a quick check of the Django version.

Now, when you narrow your search to one of the approaches, you still have many choices to consider.

All approaches work fine, and no matter the choice you use, you should stick with it. I would suggest going with basic Django’s command-line utility (one of three commands). If you need more details, use pip show django command since it lists all the essential info of the installed Django version. If you need to use the version in your code, use django.VERSION or django.get_version() depending on the format you need. The django.VERSION command returns version in tuple format, and django.get_version() returns output in string type format.