maheshgupta024
maheshgupta024

Reputation: 7877

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 successfully. But how do I check whether Django uses the 2.6 or 2.7 version and what version of modules Django uses?

Upvotes: 724

Views: 908045

Answers (30)

Manukumar
Manukumar

Reputation: 225

It's very simple open the CLI(command line or any IDE) wherever you installed python and Django just type django-admin --version, like this:

$ django-admin --version
3.1.4

Upvotes: 0

dev_light
dev_light

Reputation: 3879

To check the Django version installed on your Windows PC,

In a Terminal session, run:

py -m django --version

Or in a Python REPL:

import django
django.get_version()

To check the Django version installed in your active virtual environment (venv), run:

Django-admin --version

Note that the Django version installed on your PC might be different from the version installed in your active virtual environment.

Upvotes: 2

Zaman Kazimov
Zaman Kazimov

Reputation: 71

pip freeze | grep Django

This will give you the version of the Django which you use

Upvotes: 1

These commands below get Django version:

django-admin --version
python manage.py --version

But, these commands below get error:

django-admin -v
python manage.py -v

Upvotes: 0

Amit pratap singh
Amit pratap singh

Reputation: 149

Official Documentation

First:

python -m django --version

Second:

import django
print(django.get_version())

Upvotes: 12

Oluwafemi Tairu
Oluwafemi Tairu

Reputation: 1040

From your code, you can get the version of Django by using any of the two below.

import django
print(django.__version__)
# '3.1.5'
print(django.VERSION)
# (3, 1, 5, 'final', 0)

or from your terminal, you can run

django-admin --version

Upvotes: 1

Frank
Frank

Reputation: 2029

There are two more methods to get the Version (of Django and other packages). Both of them need a version variable for the package to get the version. According to PEP-396 the __version__variable should be set for every Python module.


Method 1 - Get version from filesystem

With that in mind, you know how to get the version for almost every Django/Python package. Look inside the __init__.py of the package root. So if you are a fast at navigating through the filesystem, this can be a very universal way of getting the Version of any package inside your site-package (virtual environment).


Method 2 - Django Debug Toolbar

There is a very helpful tool that is called django debug toolbar. If you use it (very recommendable for Django development) you can list the versions of all apps that have a package.__version__.

django-debug-toolbar-versions

Upvotes: 0

justi
justi

Reputation: 4106

If you have installed the application:

$ django-admin --version
3.2.6

Upvotes: 294

kirankumar
kirankumar

Reputation: 37

Open your CMD or Terminal and run any of the following commands

django-admin --version
        or
python3 -m django --version
        or
pip freeze

Upvotes: 1

benzene
benzene

Reputation: 59

go the setting of the Django Project. there find your Django Version.

Upvotes: -1

Javier Buzzi
Javier Buzzi

Reputation: 6808

The most pythonic way I've seen to get the version of any package:

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

This ties directly into setup.py: https://github.com/django/django/blob/master/setup.py#L37

Also there is distutils to compare the version:

>>> from distutils.version import LooseVersion, StrictVersion
>>> LooseVersion("2.3.1") < LooseVersion("10.1.2")
True
>>> StrictVersion("2.3.1") < StrictVersion("10.1.2")
True
>>> StrictVersion("2.3.1") > StrictVersion("10.1.2")
False

As for getting the python version, I agree with James Bradbury:

>>> import sys
>>> sys.version
'3.4.3 (default, Jul 13 2015, 12:18:23) \n[GCC 4.2.1 Compatible Apple LLVM 6.1.0 (clang-602.0.53)]'

Tying it all together:

>>> StrictVersion((sys.version.split(' ')[0])) > StrictVersion('2.6')
True

Upvotes: 4

yellowcap
yellowcap

Reputation: 4021

There is an undocumented utils versions module in Django:

https://github.com/django/django/blob/master/django/utils/version.py

With that, you can get the normal version as a string or a detailed version tuple:

>>> from django.utils import version
>>> version.get_version()
... 1.9
>>> version.get_complete_version()
... (1, 9, 0, 'final', 0)

Upvotes: 5

Alexander
Alexander

Reputation: 109510

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

Upvotes: 51

Avinash Bakshi
Avinash Bakshi

Reputation: 319

Run pip list in a Linux terminal and find Django and its version in the list:

Run pip freeze on cmd on Windows.

Upvotes: 7

shafikshaon
shafikshaon

Reputation: 6404

Python version supported by Django version

Django version        Python versions
----------------------------------------
1.0                   2.3, 2.4, 2.5, 2.6
1.1                   2.3, 2.4, 2.5, 2.6
1.2                   2.4, 2.5, 2.6, 2.7
1.3                   2.4, 2.5, 2.6, 2.7
1.4                   2.5, 2.6, 2.7
1.5                   2.6.5, 2.7 and 3.2.3, 3.3 (experimental)
1.6                   2.6.5, 2.7 and 3.2.3, 3.3
1.11                  2.7, 3.4, 3.5, 3.6, 3.7 (added in 1.11.17)
2.0                   3.4, 3.5, 3.6, 3.7
2.1, 2.2              3.5, 3.6, 3.7

To verify that Django can be seen by Python, type python from your shell. Then at the Python prompt, try to import Django:

>>> import django
>>> print(django.get_version())
2.1
>>> django.VERSION
(2, 1, 4, 'final', 0)

Upvotes: 3

Muhammad Shabin
Muhammad Shabin

Reputation: 531

Django version or any other package version

Open the terminal or command prompt

Type

pip show django

or

pip3 show django

You can find any package version...

Example:

pip show tensorflow

pip show numpy

etc....

Upvotes: 8

Anubhav Madhav
Anubhav Madhav

Reputation: 173

Type in your CMD or terminal:

python -m django --version

Upvotes: 11

swami
swami

Reputation: 467

Simply type python -m django --version or type pip freeze to see all the versions of installed modules including Django.

Upvotes: 18

Josh Brown
Josh Brown

Reputation: 955

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
Django==1.4.3

Upvotes: 52

bcoughlan
bcoughlan

Reputation: 26617

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)

Upvotes: 814

Brady Emerson
Brady Emerson

Reputation: 4859

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

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

Upvotes: 430

Sonia Rani
Sonia Rani

Reputation: 658

you can import django and then type print statement as given below to know the version of django i.e. installed on your system:

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

Upvotes: 1

Vishal Nagda
Vishal Nagda

Reputation: 1165

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 django-admin.py version
  3. ./manage.py --version or python manage.py --version
  4. pip freeze | grep Django
  5. python -c "import django; print(django.get_version())"
  6. python manage.py runserver --version

Django Shell Commands

  1. import django django.get_version() OR django.VERSION
  2. from django.utils import version version.get_version() OR version.get_complete_version()
  3. import pkg_resources pkg_resources.get_distribution('django').version

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

Upvotes: 22

Mark White
Mark White

Reputation: 660

After django 1.0 you can just do this

$ django-admin --version
1.11.10

Upvotes: 4

Baishakhi Dasgupta
Baishakhi Dasgupta

Reputation: 153

Type the following command in Python shell

import django
django.get_version()

Upvotes: 3

Vishnu Kiran
Vishnu Kiran

Reputation: 652

django-admin --version
python manage.py --version
pip freeze | grep django

Upvotes: 15

Amit Baderia
Amit Baderia

Reputation: 4882

You can get django version by running the following command in a shell prompt

python -m django --version

If Django is installed, you should see the version otherwise you’ll get an error telling “No module named django”.

Upvotes: 2

Mtech
Mtech

Reputation: 594

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

I am using the IDLE (Python GUI).

Upvotes: 56

Artur Barseghyan
Artur Barseghyan

Reputation: 14152

If you want to make Django version comparison, you could use django-nine (pip install django-nine). For example, if Django version installed in your environment is 1.7.4, then the following would be true.

from nine import versions

versions.DJANGO_1_7 # True
versions.DJANGO_LTE_1_7 # True
versions.DJANGO_GTE_1_7 # True
versions.DJANGO_GTE_1_8 # False
versions.DJANGO_GTE_1_4 # True
versions.DJANGO_LTE_1_6 # False

Upvotes: 2

Alex Babak
Alex Babak

Reputation: 489

You can do it without Python too. Just type this in your Django directory:

cat __init__.py | grep VERSION

And you will get something like:

VERSION = (1, 5, 5, 'final', 0)

Upvotes: 4

Related Questions