How To Check Django Version

After you install Django, it is a good idea to verify the installation by checking its version.

This is a good way of making sure you’re using the right version for your project and that Django is installed correctly in your environment.

Table of Contents

The methods I’ll show in this post work fine whether Django is installed on your computer globally or in a virtual environment. If the latter is your situation, however, first make sure, on your command line, you’re in the virtual environment and it is activated. Otherwise, Django will not be recognized as an installed module.

Check Django Version Using manage.py

We all know the python manage.py command that we use to do many things in Django like creating the superuser or running the development server. We can also use the same method to check the version of Django installed.

Run the following command on your terminal to check the Django version using manage.py:

$ python manage.py version

This will print out the version of Django on the console.

An alternative to this will be to use the django-admin command instead of the python manage.py. Below is an example:

$ django-admin --version

The first method is the one that the official Django documentation provides. You can also use the python -m method to check the Django version.

$ python -m django --version

In this command, the -m stands for ‘module’.

Check Django Version Using the Django Shell.

The Django shell is an interactive way to run Python code that you want to be compiled immediately as you hit enter.

Below is how to check the Django version using it.

$ python manage.py shell
>>> import django
>>> django.version
>>> version number

In this code snippet, we use the python manage.py shell command to get into the Django interactive shell. Once we are in there, this is shown by the >>> symbol at the beginning of each new line. Each code you run will be compiled and run at that time. Then we import Django and we use the version method to check its version.

You can also do the same in a single line like below:

$ python -c "import django; print(django.get_version())"

This will print the Django version in the Django shell, while the command has been run outside the Django shell.

Check Django Version Using Pip.

There are two methods to check the Django version using pip. One is pip show and the other is pip freeze. Let’s see them in detail:

Using Pip show.

Run the following command in your terminal to check the Django version using pip show.

$ pip show django

Unlike the other methods we have seen above, pip show does not only print out the version of Django installed, but also more information about Django including a summary of what Django is, its homepage URL, and the author’s email address. This can be some cool information to know about Django.

Using Pip freeze.

Like pip show, pip freeze does not only print the Django version installed. While pip show prints out more information about Django, pip freeze shows all the dependencies installed in your Django project and their versions.

$ pip freeze

However, it is also possible to check Django’s version alone without printing out all other dependencies. Here is how to do it:

$ pip freeze | grep Django

And that will print Django’s version.

Check Django Version Using Django Built-In Functions.

Django also comes with a few built-in methods we can use to check the version of it.

Using Django utility Functions.

Django comes with a few utility functions you can use inside your Django projects. One of them is the version method.

Since this involves importing some modules from django.utils, we have to use the Django shell in order to get the Django version.

$ python manage.py shell
>>>from django.utils import version
>>>version.get_version()

using the get_version() method returns the Django version in one format. You can also use the get_complete_version() to get it in another format.

>>> from django.utils import version
>>> version.get_complete_version()

Using Django Package resources.

We can also play around with Django’s pkg_resources to determine the version of it installed. This will also require us to use the Django shell.

$ python manage.py shell
>>> import pkg_resources
>>>pkg_resources.get_distribution('django').version

In this snippet of code, we are using the get_distrubution() function that takes an installed dependency in this case it is ‘django’ and then using the .version method to displays its version.

Check Django Version Installed In A Virtual Environment

If you want to check the Django version installed in a virtual environment, you should first cd into the virtual environment’s path, then activate the virtual environment.

When the virtual environment is active, this is shown by the name of the virtual environment enclosed in commas at the beginning of the line( Pipenv may not do so if you’re on a Windows computer).

Now that the virtual environment is activated, run any of the commands shown above in order to check the Django version installed in that virtual environment.

To learn more about virtual environments, check out the how to install Django guide.

FAQs on How To Check Django Version.

Which is the latest version of Django?

Every eight months, Django releases a major update, which means by the time you read this post, it’s probably a different version of Django than the one I’m using here. You can always keep up with Django’s versions from the Download Django page.

Which version of Python does Django use?

The official Django Project recommends you use Python 3+ for all of your Django projects.

Stephen Mclin
Stephen Mclin

Hey, I'm Steve; I write about Python and Django as if I'm teaching myself. CodingGear is sort of like my learning notes, but for all of us. Hope you'll love the content!

Articles: 125

Leave a Reply

Your email address will not be published. Required fields are marked *