{"id":1359,"date":"2022-03-09T15:02:44","date_gmt":"2022-03-09T15:02:44","guid":{"rendered":"https:\/\/zerotobyte.com\/?p=1359"},"modified":"2022-03-09T15:02:45","modified_gmt":"2022-03-09T15:02:45","slug":"how-to-check-django-version","status":"publish","type":"post","link":"https:\/\/zerotobyte.com\/how-to-check-django-version\/","title":{"rendered":"How to check Django version?"},"content":{"rendered":"\n
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.<\/strong> So how to check the Django version?<\/p>\n\n\n\n Django version can be checked using multiple approaches.<\/p>\n\n\n\n 1. Using the 2. Using 3. Using 4. Using We divide approaches of checking Django version by:<\/p>\n\n\n\n Python console commands can be used inside our Django code.<\/p>\n\n\n\n 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.<\/p>\n\n\n\n Now, when you narrow your search to one of the approaches, you still have many choices to consider.<\/p>\n\n\n\n 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).<\/strong> If you need more details, use <\/p>\n","protected":false},"excerpt":{"rendered":" Django is one of the most popular framework for creating web applications. Its initial release was back in 2005, and … <\/p>\ndjango-admin<\/code> command line (terminal commands)<\/strong><\/p>\n\n\n\n
$ django-admin version\n4.0.3<\/pre>\n\n\n\n
$ python manage.py version\n4.0.3<\/pre>\n\n\n\n
$ python -m django version\n4.0.3<\/pre>\n\n\n\n
django<\/code> module (Python console commands)<\/strong><\/p>\n\n\n\n
>>> import django\n>>> django.VERSION\n(4, 0, 3, 'final', 0)<\/pre>\n\n\n\n
>>> import django\n>>> django.get_version()\n'4.0.3'<\/pre>\n\n\n\n
pip<\/code> (terminal commands)<\/strong><\/p>\n\n\n\n
$ pip show django\nName: Django\nVersion: 4.0.3\nSummary: A high-level Python web framework that encourages rapid development and clean, pragmatic design.\nHome-page: https:\/\/www.djangoproject.com\/\nAuthor: Django Software Foundation\nAuthor-email: foundation@djangoproject.com\nLicense: BSD-3-Clause\nLocation:...\/venv\/lib\/python3.8\/site-packages\nRequires: asgiref, backports.zoneinfo, sqlparse\nRequired-by: <\/pre>\n\n\n\n
$ pip freeze | grep Django\nDjango==4.0.3<\/pre>\n\n\n\n
pkg_resources<\/code> module (Python console command)<\/strong><\/p>\n\n\n\n
>>> import pkg_resources\n>>> pkg_resources.get_distribution('django').version\n'4.0.3'<\/pre>\n\n\n\n
What method should I use?<\/h2>\n\n\n\n
When to use terminal commands?<\/strong><\/td> When to use Python console commands?<\/strong><\/td><\/tr> Use it when output is not required later in the code.<\/td> Use it when your code depends on the output of the given method.<\/td><\/tr> Use it for a quick check of the Django version.<\/td> <\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n pip show django<\/code> 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<\/code> or
django.get_version()<\/code> depending on the format you need. The
django.VERSION <\/code>command returns version in tuple format, and
django.get_version()<\/code> returns output in string type format.<\/p>\n\n\n\n