794π
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)
423π
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
- [Django]-Python Asyncio in Django View
- [Django]-Django F() division β How to avoid rounding off
- [Django]-What is the purpose of adding to INSTALLED_APPS in Django?
- [Django]-How can I chain Django's "in" and "iexact" queryset field lookups?
- [Django]-Celery discover tasks in files with other filenames
- [Django]-POST jQuery array to Django
- [Django]-How can I temporarily disable a foreign key constraint in MySQL?
- [Django]-How to test Django's UpdateView?
- [Django]-Get user profile in django
55π
>>> import django
>>> print(django.get_version())
1.6.1
I am using the IDLE (Python GUI).
- [Django]-Uwsgi installation error in windows 7
- [Django]-Has Django served an excess of 100k daily visits?
- [Django]-Django-way for building a "News Feed" / "Status update" / "Activity Stream"
51π
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
- [Django]-How do I install psycopg2 for Python 3.x?
- [Django]-Django Admin app or roll my own?
- [Django]-How do I run tests against a Django data migration?
49π
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
- [Django]-Django: Reference to an outer query may only be used in a subquery
- [Django]-__init__() got an unexpected keyword argument 'mimetype'
- [Django]-Error: No module named staticfiles
38π
For Python:
import sys
sys.version
For Django (as mentioned by others here):
import django
django.get_version()
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'
False
The solution is to use StrictVersion from distutils.
>>> from distutils.version import StrictVersion
>>> StrictVersion('1.7.5') < StrictVersion('1.7.10')
True
- [Django]-Django Queryset with year(date) = '2010'
- [Django]-Django: Open uploaded file while still in memory; In the Form Clean method?
- [Django]-Macros in django templates
22π
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
python -m django --version
django-admin --version
ordjango-admin.py version
./manage.py --version
orpython manage.py --version
pip freeze | grep Django
python -c "import django; print(django.get_version())"
python manage.py runserver --version
Django Shell Commands
import django
OR
django.get_version()
django.VERSION
from django.utils import version
OR
version.get_version()version.get_complete_version()
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.)
- [Django]-Stack trace from manage.py runserver not appearing
- [Django]-Django QuerySet order
- [Django]-How to implement followers/following in Django
18π
Simply type python -m django --version
or type pip freeze
to see all the versions of installed modules including Django.
- [Django]-Migrating Django fixtures?
- [Django]-Django model CharField: max_length does not work?
- [Django]-Python Asyncio in Django View
- [Django]-Django β how to unit test a post request using request.FILES
- [Django]-Django create userprofile if does not exist
- [Django]-How to get username from Django Rest Framework JWT token
13π
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 manage.py runserver --version
- [Django]-Combining Django F, Value and a dict to annotate a queryset
- [Django]-Are sessions needed for python-social-auth
- [Django]-What is a django.utils.functional.__proxy__ object and what it helps with?
- [Django]-Choose test database?
- [Django]-Altering one query parameter in a url (Django)
- [Django]-How to use regex in django query
11π
Official Documentation
First:
python -m django --version
Second:
import django
print(django.get_version())
- [Django]-Constructing Django filter queries dynamically with args and kwargs
- [Django]-Uwsgi installation error in windows 7
- [Django]-How do you dynamically hide form fields in Django?
8π
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β¦.
- [Django]-Sending post data from angularjs to django as JSON and not as raw content
- [Django]-Switching to PostgreSQL fails loading datadump
- [Django]-How to tell if a task has already been queued in django-celery?
7π
Run pip list
in a Linux terminal and find Django and its version in the list:
Run pip freeze
on cmd on Windows.
- [Django]-Django Sitemaps and "normal" views
- [Django]-How to test Django's UpdateView?
- [Django]-How can I get tox and poetry to work together to support testing multiple versions of a Python dependency?
6π
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.
- [Django]-Django datefield filter by weekday/weekend
- [Django]-Unittest Django: Mock external API, what is proper way?
- [Django]-Django: Arbitrary number of unnamed urls.py parameters
5π
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)
- [Django]-Disabled field is not passed through β workaround needed
- [Django]-Sending HTML email in django
- [Django]-How to access request body when using Django Rest Framework and avoid getting RawPostDataException
4π
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)
- [Django]-How to test "render to template" functions in django? (TDD)
- [Django]-Use Python standard logging in Celery
- [Django]-Referencing multiple submit buttons in django
4π
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
- [Django]-How can I temporarily disable a foreign key constraint in MySQL?
- [Django]-Django 2 β How to register a user using email confirmation and CBVs?
- [Django]-Django: Example of generic relations using the contenttypes framework?
- [Django]-405 "Method POST is not allowed" in Django REST framework
- [Django]-Why does django run everything twice?
- [Django]-Django annotation with nested filter
3π
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)
- [Django]-Django annotation with nested filter
- [Django]-Django celery task: Newly created model DoesNotExist
- [Django]-How to upload a file in Django?
2π
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
- [Django]-How do I use an UpdateView to update a Django Model?
- [Django]-Why is logged_out.html not overriding in django registration?
- [Django]-How to check if ManyToMany field is not empty?
2π
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β.
- [Django]-How can I activate the unaccent extension on an already existing model
- [Django]-Django project models.py versus app models.py
- [Django]-Visual Editor for Django Templates?
2π
Type the following command in Python shell
import django
django.get_version()
- [Django]-Constructing Django filter queries dynamically with args and kwargs
- [Django]-How to get an ImageField URL within a template?
- [Django]-Celery. Decrease number of processes
1π
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
- [Django]-Django Footer and header on each page with {% extends }
- [Django]-Why does django run everything twice?
- [Django]-Sending an SMS to a Cellphone using Django
1π
Open your CMD or Terminal and run any of the following commands
django-admin --version
or
python3 -m django --version
or
pip freeze
- [Django]-How to tell if a task has already been queued in django-celery?
- [Django]-Django Admin Form for Many to many relationship
- [Django]-How to pass multiple values for a single URL parameter?
1π
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
- [Django]-Remove Labels in a Django Crispy Forms
- [Django]-Override existing Django Template Tags
- [Django]-Django: list all reverse relations of a model
0π
Itβs very simple open the CLI(command line or any IDE) wherever you installed python and Django just type,
django-admin βversion
see here I have installed the latest Python and Django in my system and the result is shown in fig.
- [Django]-How to recursively query in django efficiently?
- [Django]-Parsing unicode input using python json.loads
- [Django]-UUID as default value in Django model
0π
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]-Django 2 β How to register a user using email confirmation and CBVs?
- [Django]-Using Cloudfront with Django S3Boto
- [Django]-Iterating over related objects in Django: loop over query set or use one-liner select_related (or prefetch_related)
0π
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
- [Django]-How to resize the new uploaded images using PIL before saving?
- [Django]-Filtering dropdown values in django admin
- [Django]-Django QuerySet order
0π
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.
- [Django]-Is this the right way to do dependency injection in Django?
- [Django]-Get user profile in django
- [Django]-Add rich text format functionality to django TextField
- [Django]-What is the purpose of adding to INSTALLED_APPS in Django?
- [Django]-How can I get tox and poetry to work together to support testing multiple versions of a Python dependency?
- [Django]-Django Rest JWT login using username or email?