Welcome Django user, In one of my posts I show you step-by-step how to install Django. However, I do not cover much on how to check the Django version installed on your computer either globally or in a virtual environment. Checking your Django version installed is a good way of making sure you’re using the right version for your project and it’s just good to know if you’re searching for some answers from the Internet. It is also the best way to know if Django is installed correctly on your machine or virtual environment. This post is going to show you that. In this post, I’ll share with you 5 methods to check the Django version.
Let’s get started.
Table of Contents
- How To Check Django Version Using Django Scripts.
- How To Check Django Version Using the Django Shell.
- How To Check Django Version Using Pip.
- How To Check Django Version Using Django Built-In Functions.
- How To Check Django Version Installed In A Virtual Environment
- Frequently Asked Questions: How To Check Django Version.
- Conclusion: How To Check Django Version.
The methods I’ll show in this post work fine whether Django is installed on your computer globally or it is installed 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.
How To Check Django Version Using Django Scripts.
We all know the
python manage.py command that we use when wanting 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 to do that:
$ 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 the example:
$ django-admin --version
The above 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’.
How To 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.
How To 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:
How To Check Django Version Using Pip show.
Run the following command in your terminal to check the Django version using
$ 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.
How To Check Django Version Using Pip freeze.
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, and that is including Django.
$ 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.
How To 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.
How To Check Django Version Using Django utility Functions.
Django comes with a few utility functions you can use inside your Django projects. One of them is the
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()
get_version() method returns the Django version in this format. You can also use the
get_complete_version() to get this format.
>>> from django.utils import version >>> version.get_complete_version()
How To Check Django 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 need 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.
How To 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.
Frequently Asked Questions: How To Check Django Version.
Which is the latest version of Django?
As of the writing of this post, the latest Django version is Django 4.0.5, as you can see in the examples I provide. 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. 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.
Conclusion: How To Check Django Version.
The methods I’ve shared with you in this article are sourced from other developer sites like Stack Overflow and you can see its a lot of them (I’m not even sure if these are all there is to check the Django version). I personally use a few of them and I recommend you do so as well. Sticking to one is even better, you can always use the rest when really needed (maybe in the code). This post might help you pick the best one for you, pick the one that is both easy and faster to type out and that returns the results in a way you understand.
It’s most probable that these methods to check the Django version are not all there is. If you ever have a method that you think deserves to be on this list, please share it in the comments section below. And if these mentioned methods do not work for you, let me know again in the comments section. Otherwise, please share this post with fellow Django developers who may need to know about it. Peace!