In this Django tutorial, you will understand about how to change the Django version. First, you will learn ‘What is the reason behind changing the Django version?’.
After that, you will understand how to check the current version of installed Django using different methods. Then I will show you how to change the Django version to the new version and downgrade the Django version to a particular version.
Finally, you will understand how to change the Django version using an IDE such as PyCharm.
Reasons to change Django Version
While changing the Django version is a complex process, it has several benefits also. So in this section, we’ll learn the reasons for upgrading the Django version.
- Additional features have been added.
- Improvements have been made.
- The bugs have been fixed.
- Updating as each current Django release becomes available reduces the agony of future upgrades by keeping your code up to date
- “Long Term Support” (LTS) versions are indicated on some Django framework releases. For three years, LTS versions received security and bug patches. The security risk on your website grows if you use an unsupported version of Django.
- It defends your website against cyber-attacks.
- Maintain your server at all times.
- Protect your data from unauthorized access and theft.
- Benefits development teams in terms of productivity.
- It also helps your development staff to spend less time and money on security and bugs.
- It also liberates your development team to concentrate on website upgrades or revenue-generating projects.
Also, read: Python Django vs Flask
How to check the Django Version
You should know which version of Django you’re using before changing the version. There are different ways to check the version of Django.
The first way to find out what the Django version is is to start your Django server if you have created the project. To start the Django server use the following command in your terminal.
python manage.py runserver
The command ‘python manage.py runserver’ starts the Django server and shows the information about the Django server such as on which IP address or port the Django server ‘http://127.0.0.1:8000’ is running.
Also shows the started timing of the Django server ‘February 03, 2022 – 18:09:57’ and the Django version that you can see in the above output something like this ‘Django version 4.0.1’
Now you know the current Django version is 4.0.1. This is the one way to check the version of Django.
The second way is to check the Django version using the freeze command. This freeze command list all the package that you install for your Django project including the Django framework.
So run the below command in your terminal to list all the installed packages within your Django project.
As soon as you run the above command it shows all the packages that you have installed in your environment.
In the above output, you can see the current version of Django is 4.0.1.
The third way to check the Django version is by using the Python shell. So to open the Python shell type the below command in your terminal.
python manage.py shell
The above command takes you to the Python shell where you can write the Python code. But here you need to know about how to check the Django version. So type the following code in your Python shell.
import django django.get_version()
In the above code within the python shell, the code import django imports the Django module in the current python shell. Then use the method get_version() of Django to check the current version of installed Django.
As you can see in the output the current version of the Django is 4.0.1.
The fourth and last way to check the Django version is the command that is shown below.
python manage.py version
To acquire the Django version, first, stop the server (if you haven’t already), then open a terminal window and type the command mentioned above.
As you can see in the output, the command ‘python manage.py version’ shows only the version of the currently installed Django which is 4.0.1.
Now you know different ways or methods to check the version of Django, let’s move to the next topic to change the version of the currently installed Django.
Read: How to install Django
Python change Django Version
In this section, you will learn a few possible ways to change the Django version. You can update the Django version to the most recent version or downgrade the Django version to an older version or previous version.
First, let’s see how to update the Django version.
Update Django Version
In many instances, you’ll need to update your Django-related dependencies to the newest version. Some of your dependencies may not yet support the new Django version that was newly released or dependencies aren’t up to date.
In certain cases, you may need to wait until updated versions of your dependencies are released.
Below are three commands that you can run in your terminal or command prompt to update the Django version.
pip install django --upgrade #OR python -m pip install -U django #OR python -m pip install --upgrade django
Open your terminal and check the current version of Django by running the below command.
python manage.py version
As you can see the current version of Django is 3.2.12, let’s update the Django version to the latest version.
Open a terminal window and type any of the commands listed above. It will upgrade to the most recent version of Django and uninstall the previous version automatically.
For example, run the below command in your terminal.
python install --upgrade django
The outputs demonstrate that it removes the 3.2.12 version and replaces it with the most recent release, 4.0.2. Now you know how to update the Django version.
Let’s move and learn how to downgrade the Django version to an older version.
Downgrade Django Version
Downgrading the Django version is not a good idea, but if there are particular needs that demand it, you can do so. The commands listed below are used to downgrade the version as well as change the version to a specified one.
pip install django==<specific version> #OR pip install --upgrade django==<specific version>
First, check the current version of Django using the below command.
python manage.py version
As you can see the current version of Django is 4.0.2, so to downgrade the Django version to a specific version such as 3.1.14. Use the below command.
pip install django==3.1.14
As soon as you hit enter from your keyboard, the current version 4.0.2 of Django is uninstalled and the specific version such as 3.1.14 is installed as you can see in the above output.
Also, use the second command to downgrade the Django version as shown below.
pip install --upgrade django==3.2.12
This is how you can change the Django version to a recent and old version. But sometimes you use the IDE for the project development such as Visual Studio, PyCharm, etc.
How you can change the Django version using these IDE, the next section is about how to change the Django version in IDE (Integrated Development Environment).
Change Django Version Using PyCharm
In this section, you will learn how to use the PyCharm editor using GUI to change the Django version to a specified version.
The following steps are used:
- PyCharm Editor should now be open.
- On the top right bar, select File. Then go to the Settings tab.
- First, we need to select the Project.
- Then, under the project, select Python Interpreter.
- Then double-click on the Django package to open it.
- Select the version you want by checking the box Specify version.
- Install the package by pressing the Install Package button.
- In the backend, the pip command installs a specific version of Django.
To install a specific version of Django, you can simply use the pip commands that you have learned in the previous sections.
In this Python Django tutorial, you learned how to change the Django version. First, you learned different ways that you can use to check the current Django version. Then learned how to update or downgrade the Django version using different commands. Finally, you learned how to change the Django version using the IDE PyCharm.
You may also like to read the following Django tutorials.
- Python Django get admin password
- Python Django set timezone
- How to get user IP address in Django
- Login system in Python Django
- How to Create model in Django
I am Bijay Kumar, a Microsoft MVP in SharePoint. Apart from SharePoint, I started working on Python, Machine learning, and artificial intelligence for the last 5 years. During this time I got expertise in various Python libraries also like Tkinter, Pandas, NumPy, Turtle, Django, Matplotlib, Tensorflow, Scipy, Scikit-Learn, etc… for various clients in the United States, Canada, the United Kingdom, Australia, New Zealand, etc. Check out my profile.