- How to check your Django version
- Option 1
- Option 2
- Option 3
- Option 4
- Change the Django version
- How to check Django version?
- What method should I use?
- Recent Posts
- Проверить версию Django
- Проверить версию Django
- Проверить версию Django с помощью команды python
- Проверить версию Django с помощью команды django-admin
- Проверить версию Django с помощью файла manage.py
- How can I check Django version?
- Checking Django version with Idle
- Checking Django version with pip
- Upgrade Django version
- Downgrade Django version
How to check your Django version
There are multiple ways to check what Django version you are on. Some are easier than others. I will go over 4 options, if they all don’t work for you, comment below and I will try to help you out.
Option 1
When you start your server ( python manage.py runserver ), you will get some output right away. That will also tell you on what version you are. Look at the sample data below.
Watching for file changes with StatReloader Performing system checks. System check identified no issues (0 silenced). November 20, 2019 - 14:34:16 Django version 2.2.5, using settings 'back.settings' Starting ASGI/Channels version 2.3.0 development server at http://127.0.0.1:8000/ Quit the server with CONTROL-C.
There it says: Django version 2.2.5, using settings ‘back.settings’ , so your Django version is 2.2.5.
Option 2
Stop the server and then run pip freeze | grep Django (when you are in the virtual environment). The output should be something like this:
Django is shown there as Django==2.2.5 , which means that Django is currently on version 2.2.5 .
Option 3
Stop the server (if you haven’t already) and open up shell python manage.py shell and then enter this:
import django django.get_version()
For me, it prints out 2.2.5 , which then is your Django version.
Option 4
Stop the server (if you haven’t already) and then run this:
Change the Django version
If you want to upgrade Django, then you can run pip install —upgrade django . If you would like to downgrade, then you can run pip install django== . Replace with the actual number, like 2.2.1 .
I hope this helps you out.
Stan is professional web developer working mainly with Django and VueJS. With years of experience under the belt, he is comfortable writing about his past mistakes and ongoing learnings.
How to check Django version?
Django is one of the most popular framework for creating web applications. Its initial release was back in 2005, and since then, more than 20 stable versions have been released. Having that many versions available to choose from, we often require methods to check our version in Django, either for deployment or dependency compatibility purposes. So how to check the Django version?
Django version can be checked using multiple approaches.
1. Using the django-admin command line (terminal commands)
$ python manage.py version 4.0.3
$ python -m django version 4.0.3
2. Using django module (Python console commands)
>>> import django >>> django.VERSION (4, 0, 3, 'final', 0)
>>> import django >>> django.get_version() '4.0.3'
3. Using pip (terminal commands)
$ pip show django Name: Django Version: 4.0.3 Summary: A high-level Python web framework that encourages rapid development and clean, pragmatic design. Home-page: https://www.djangoproject.com/ Author: Django Software Foundation Author-email: foundation@djangoproject.com License: BSD-3-Clause Location. /venv/lib/python3.8/site-packages Requires: asgiref, backports.zoneinfo, sqlparse Required-by:
$ pip freeze | grep Django Django==4.0.3
4. Using pkg_resources module (Python console command)
>>> import pkg_resources >>> pkg_resources.get_distribution('django').version '4.0.3'
We divide approaches of checking Django version by:
Python console commands can be used inside our Django code.
What method should I use?
There is a big difference between Python console and terminal commands. So firstly, you should narrow your search of methods to one of the provided approaches.
When to use terminal commands? | When to use Python console commands? |
Use it when output is not required later in the code. | Use it when your code depends on the output of the given method. |
Use it for a quick check of the Django version. |
Now, when you narrow your search to one of the approaches, you still have many choices to consider.
All approaches work fine, and no matter the choice you use, you should stick with it. I would suggest going with basic Django’s command-line utility (one of three commands). If you need more details, use pip show django command since it lists all the essential info of the installed Django version. If you need to use the version in your code, use django.VERSION or django.get_version() depending on the format you need. The django.VERSION command returns version in tuple format, and django.get_version() returns output in string type format.
Recent Posts
Проверить версию Django
- Проверить версию Django
- Проверить версию Django с помощью команды python
- Проверить версию Django с помощью команды django-admin
- Проверить версию Django с помощью файла manage.py
В этой статье мы обсудим, как проверить версию библиотеки Django.
Прежде чем мы продолжим, обратите внимание на два ключевых момента.
- Убедитесь, что на вашем компьютере установлены библиотеки Python и Django или, если вы используете виртуальную среду, не забудьте переключиться на нее. В противном случае Python выдаст ошибку, что Django не существует.
- На всех выходах вместо цифр будет X , потому что версия у всех может быть разной.
Проверить версию Django
Проверить версию библиотеки Django с помощью Python — несложная задача. Интересно, что есть четыре пути, которыми мы можем действовать. Во всех методах мы будем использовать некоторые функции из библиотеки Django.
См. Следующий фрагмент кода.
import django from django.utils import version print(django.VERSION) print(django.get_version()) print(version.get_complete_version()) print(version.get_version())
(X, X, X, 'final', X) 'X.X' (X, X, X, 'final', X) 'X.X'
Атрибут VERSION Django и трех других функций, а именно get_version() , utils.version.get_complete_version() и utils.version.get_version() может использоваться для проверки версии Django.
Проверить версию Django с помощью команды python
Мы всегда можем вызвать Python и выполнить код Python прямо из командной строки, используя следующий синтаксис.
python [-bBdEhiIOqsSuvVWx?] [-c command | -m module-name | script | - ] [args]
У этой команды есть несколько параметров, но мы будем использовать только два варианта для проверки версии библиотеки Django.
Используя опцию -c или command , мы можем выполнить один или несколько операторов Python, разделенных новой строкой, прямо из командной строки. Эти утверждения должны быть заключены в двойные кавычки «» .
См. Следующие команды. Мы выполним код Python из предыдущего раздела прямо из командной строки.
python -c "import django; print(django.VERSION)" python -c "import django; print(django.get_version())" python -c "from django.utils import version print(version.get_complete_version())" python -c "from django.utils import version print(version.get_version())"
(X, X, X, 'final', X) X.X (X, X, X, 'final', X) X.X
Используя опцию -m или module-name , мы можем получить доступ к модулю Python и использовать его опции для проверки метаданных модуля. —version используется для проверки версии модуля.
Обратитесь к следующей команде.
Проверить версию Django с помощью команды django-admin
Мы также можем использовать команду django-admin для печати версии библиотеки Django. Мы воспользуемся опцией —version или version этой команды, чтобы проверить версию модуля.
django-admin version django-admin --version
Проверить версию Django с помощью файла manage.py
Если вы когда-либо создавали проект Django, вы бы знали, что внутри каталога проекта всегда существует файл manage.py . Это важный файл, и мы рекомендуем не связываться с ним. Тем не менее, мы всегда можем использовать этот файл для печати версии библиотеки Django, точно так же, как при запуске сервера Django.
Обратитесь к следующей команде.
Vaibhav is an artificial intelligence and cloud computing stan. He likes to build end-to-end full-stack web and mobile applications. Besides computer science and technology, he loves playing cricket and badminton, going on bike rides, and doodling.
How can I check Django version?
The way you check your Django version depends on if you installed Django on you base python installation or you installed the module in a virtual environment. Let’s see first how to check your version on the base python installation.
Checking Django version with Idle
import django django.get_version()
You could also use the following code, that will return the same results, but slightly different format:
import django django.VERSION
Checking Django version with pip
Django==3.0.8 # Django version docutils==0.14 dominate==2.5.1 Flask==1.1.1 Flask-Bootstrap==3.3.7.1 importlib-metadata==1.6.0
If django is in your python installation, it will be listed along with any other module installed. Check out your django version in a virtualenv or using the django scripts
Upgrade Django version
You can upgrade django and any module installed using the pip command. You can run the following command from your terminal, or the Pycharm terminal. As before, if you are working on a virtual environment, make sure you activate the environment before running the command:
pip install --upgrade django
Downgrade Django version
pip install -v Django==3.0.5 #Replace with your version
You can find a list with all the available django version here As before in case you are working on a virtualenv, make sure it is activated. Or if you have several python version installed in your computer, make sure your pip command you are using belongs to the python installation you are using to run your python program. You can check this by running the linux which command from your terminal.
The output should be same folder or subfolder as where your python version is installed. Check out the following article to see how to install and uninstall python, and see your local python version