0
0
DjangoHow-ToBeginner · 3 min read

How to Check Django Version Quickly and Easily

You can check the Django version by running django-admin --version in your terminal or by running python -m django --version. Alternatively, inside a Python script or shell, import Django and print django.get_version().
📐

Syntax

There are two main ways to check the Django version:

  • Command line: Run django-admin --version or python -m django --version in your terminal.
  • Python code: Import Django and call django.get_version() to get the version string.

These methods show the installed Django version in your current environment.

bash
django-admin --version

# or

python -m django --version

# In Python shell or script
import django
print(django.get_version())
Output
4.2.3
💻

Example

This example shows how to check the Django version inside a Python script or interactive shell.

python
import django

version = django.get_version()
print(f"Django version is {version}")
Output
Django version is 4.2.3
⚠️

Common Pitfalls

Common mistakes when checking Django version include:

  • Running django-admin --version outside the virtual environment where Django is installed, which may show an incorrect or no version.
  • Trying to check version without Django installed, which causes errors.
  • Confusing the Django project version with the Django package version.

Always activate your virtual environment before checking the version.

bash
## Wrong way (outside virtual environment)
# django-admin --version
# Output: command not found or wrong version

## Right way (inside virtual environment)
# source venv/bin/activate
# django-admin --version
# Output: 4.2.3
📊

Quick Reference

Summary of commands to check Django version:

MethodCommand/CodeDescription
Command Linedjango-admin --versionShows Django version in terminal
Command Linepython -m django --versionAlternative terminal command
Python Codeimport django; django.get_version()Get version inside Python code

Key Takeaways

Use django-admin --version or python -m django --version in terminal to check Django version.
Inside Python, import Django and call django.get_version() to get the version string.
Always activate your virtual environment before checking the version to get accurate results.
If Django is not installed, these commands will not work and will show errors.
Checking version helps ensure compatibility and debugging in your Django projects.