How to check Django version

How to check Django version

I have to use Python and Django for our application. So I have two versions of Python, 2.6 and 2.7. Now I have installed Django. I could run the sample application for testing Django succesfuly. But how do I make sure whether Django uses the 2.6 or 2.7 version and what version of modules Django uses?


Answer 1:

Django 1.5 supports Python 2.6.5 and later.

If you’re under Linux and want to check the Python version you’re using, run python -V from the command line.

If you want to check the Django version, open a Python console and type

>>> import django
>>> django.VERSION
(2, 0, 0, 'final', 0)

Answer 2:

Basically the same as bcoughlan’s answer, but here it is as an executable command:

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

Answer 3:

If you have installed the application:

$ version

Answer 4:

Go to your Django project home directory and do:

./ --version

Answer 5:

>>> import django
>>> print(django.get_version())

I am using the IDLE (Python GUI).

Answer 6:

If you have pip, you can also do a

pip freeze

and it will show your all component version including Django .

You can pipe it through grep to get just the Django version. That is,

josh@villaroyale:~/code/djangosite$ pip freeze | grep Django

Answer 7:

For Python:

import sys

For Django (as mentioned by others here):

import django

The potential problem with simply checking the version, is that versions get upgraded and so the code can go out of date. You want to make sure that ‘1.7’ < ‘1.7.1’ < ‘1.7.5’ < ‘1.7.10’. A normal string comparison would fail in the last comparison:

>>> '1.7.5' < '1.7.10'

The solution is to use StrictVersion from distutils.

>>> from distutils.version import StrictVersion
>>> StrictVersion('1.7.5') < StrictVersion('1.7.10')

Answer 8:

Type the following at the command prompt: version

If django is installed it will print its current version (eg. 1.6.5),
otherwise the shell will print an error message.

Answer 9:

As you say you have two versions of python, I assume they are in different virtual environments (e.g. venv) or perhaps conda environments.

When you installed django, it was likely in only one environment. It is possible that you have two different versions of django, one for each version of python.

In from a Unix/Mac terminal, you can check your python version as follows:

$ python --version

If you want to know the source:

$ which python

And to check the version of django:

$ python -m django --version

Answer 10:

There are various ways to get the Django version. You can use any one of the following given below according to your requirements.

Note: If you are working in a virtual environment then please load your python environment

Terminal Commands

  1. python -m django --version
  2. django-admin --version or version
  3. ./ --version or python --version
  4. pip freeze | grep Django
  5. python -c "import django; print(django.get_version())"
  6. python runserver --version

Django Shell Commands

  1. import django
  2. from django.utils import version
    OR version.get_complete_version()
  3. import pkg_resources

(Feel free to modify this answer, if you have some kind of correction or you want to add more related information.)

Answer 11:

For checking using a Python shell, do the following.

>>>from django import get_version
>>> get_version()

If you wish to do it in Unix/Linux shell with a single line, then do

python -c 'import django; print(django.get_version())'

Once you have developed an application, then you can check version directly using the following.

python runserver --version

Answer 12:

django-admin --version
python --version
pip freeze | grep django

Answer 13:

Django will use the version of Python specified by the PYTHONPATH environment variable. You can use echo $PYTHONPATH in a shell to determine which version will be used.

The module versions used by Django will be the module versions installed under the version of Python specified by PYTHONPATH.

Answer 14:

run pip list on LINUX TERMINAL and find Django and its version on list

run pip freeze on cmd on Windows