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
4.0.3
$ python manage.py version
4.0.3
$ python -m django version
4.0.3

2. Using django module (Python console commands)

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

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.
Home-page: https://www.djangoproject.com/
Author: Django Software Foundation
Author-email: foundation@djangoproject.com
License: BSD-3-Clause
Location:.../venv/lib/python3.8/site-packages
Requires: asgiref, backports.zoneinfo, sqlparse
Required-by: 
$ pip freeze | grep Django
Django==4.0.3

4. Using pkg_resources module (Python console command)

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

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
 commands.

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.