Tips for upgrading Python/Django versions in existing apps

Unlock the power of the latest Python and Django versions with expert tips for seamlessly upgrading your existing apps.

Python is a robust and powerful programming language. In addition to machine learning, Python can be used for tasks such as web scraping, image processing, scientific computing, and much more. A framework such as Django, which is built on top of Python, enables you to build beautiful web applications—top websites such as Dropbox, Instagram, and YouTube use Django.

However, as you create applications and release them to consumers, you need to keep an eye out for updates or new features that are guaranteed to come. For instance, Python 3.11 was released in October 2022 sporting various bug fixes. Before that, there was Python 3.10, 3.9, 3.8, you get the picture. There are also numerous third-party libraries that you should regularly watch out for.

Incorporating these updates into our applications can be beneficial, as the former can enhance the security and reliability of the latter. However, doing this incorrectly could also break your application.

Read on to learn why you should always upgrade your application or project for use with the latest versions of Python or Django. Plus, get to know the best practices and tips for upgrading your Python/Django application.

Why you should upgrade

Upgrading your Python and Django applications to the latest version is important for several reasons.

First, new versions come with additional features and improvements. For instance, newer Django versions can help reduce boilerplate code, enabling you to develop and push products to the market much faster. New versions also help you learn new ways of adding functionalities to your application that can be more fun, rewarding, and easier to implement.

Second, new versions can help fix some of the bugs in your code. Apart from enabling your application to behave as expected, eliminating bugs also streamlines the software development process, meaning that you'll be less frustrated. An upgrade can also improve your app's stability during production.

Third, upgrading your application also makes it easier to maintain your codebase. You can quickly incorporate changes in your project without suffering major downtimes.

Fourth, ensuring you're using the latest Python or Django version also boosts your application's security. Hackers are continuously looking for new ways to infiltrate systems, steal data, install malicious files and viruses, and just wreak havoc. Upgrading your application to use the latest version of Python or Django ensures that you're always a step ahead.

Now that we understand why upgrading applications is necessary, let's jump into the action itself.

Things to know before upgrading

Before updating your application to the latest version, you must first read about the changes in the new update. Go through the official documentation, particularly the release notes. Note that with each new version, Django releases accompanying documentation, which is quite helpful when upgrading applications.

Next, look at the functions, objects, and other important concepts deprecated in the new update. Consider the deadline or timeline in which these deprecation changes are set to come into effect. Understanding the deprecation timeline allows you to better plan your upgrade process, including the prioritization of certain tasks over others.

You should also keep an eye on backwards compatibility. Remember that some things that work in your existing application may fail when you upgrade to a new version. This is why it's recommended to test things first before pushing to production. Whenever an upgrade causes your app to break, you can roll back to the previous version as you figure out the next steps.

How to upgrade Python/Django apps

In this section, we will learn how to upgrade a simple Django Movie API to use the latest version. You can download the project's code from this GitHub repository.

Check Django and other library versions

Once you've downloaded the Movie API project and finished setting it up on your computer, the first step is to check the versions of the dependencies that the project uses.

To do this, launch the project in your preferred code editor and open the requirements.txt file. All dependencies used by the project are listed in this file, as follows.


Since we now know the versions in use (shown above), the next step is to determine the current official version from the documentation. For instance, the latest official Django version is 4.2.1; our application uses an older version (3.1.8), so there's a need to upgrade.

Activate local debugging

Trying to update things in production could cause them to break and lead to poor user experience and other negative consequences. To avoid such issues, you must test your applications locally and ensure that everything is working before pushing them to production.

You can activate local debugging by setting the debug option in the file to True.

import os

# Build paths inside the project like this: os.path.join(BASE_DIR, …)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

# Quick-start development settin–s - unsuitable for production
# See

# SECURITY WARNING: Don’t run with debug turned on in production!
DEBUG = True  # Set debug to true


Run Django checks with python -Wall check

Before starting the upgrade, we'll need to run several checks to determine if there are any deprecation warnings in our project.

Deprecation warnings show that certain features will stop working at some point simply because they have been replaced by better alternatives.

You can check for any warnings using the following command:

python -Wa test

Install new dependencies

Now that we have enabled local debugging and have identified any deprecation warnings in our project, it's time to install new dependencies in our project.

To get the latest Django version, we use the following command.

python -m pip install -U Django

When you run the above command, the following output should appear in your terminal. We have now successfully updated Django to ver 4.2.1, asgiref to ver 3.6.0, and tzdata to ver 2023.3.

Requirement already satisfied: Django in c:\users\wanjamike\appdata\local\programs\python\python310\lib\site-packages (3.1.8)
Collecting Django
  Downloading Django-4.2.1-py3-none-any.whl (8.0 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 8.0/8.0 MB 43.5 kB/s eta 0:00:00
Requirement already satisfied: sqlparse>=0.3.1 in c:\users\wanjamike\appdata\local\programs\python\python310\lib\site-packages (from Django) (0.4.1)
Collecting tzdata
  Using cached tzdata-2023.3-py2.py3-none-any.whl (341 kB)
Collecting asgiref<4,>=3.6.0
  Using cached asgiref-3.6.0-py3-none-any.whl (23 kB)
Installing collected packages: tzdata, asgiref, Django
  Attempting uninstall: asgiref
    Found existing installation: asgiref 3.3.1
    Uninstalling asgiref-3.3.1:
      Successfully uninstalled asgiref-3.3.1
  Attempting to uninstall: Django
    Found existing installation: Django 3.1.8
    Uninstalling Django-3.1.8:
      Successfully uninstalled Django-3.1.8
Successfully installed Django-4.2.1 asgiref-3.6.0 tzdata-2023.3

We can update the remaining dependencies in our project using the following command:

python -m pip install -U django-filter djangorestframework djangorestframework-simplejwt pytz sqlparse

Expected output:

Successfully installed django-filter-23.2 djangorestframework-3.14.0 djangorestframework-simplejwt-5.2.2 pytz-2023.3 sqlparse-0.4.4

Let's generate a new requirements.txt file and double-check that we have the latest libraries in our project.

pip freeze > requirements.txt

When you open the requirements.txt, you should find all the latest dependencies, as shown below:


Check methods and functions

In most software updates, developers will try to change how certain functions or components work to improve performance, efficiency, or convenience. Rather than fighting such changes, consider embracing and integrating them into your application to realize their benefits.

Note that while this may be a time-consuming step, the benefits are worth it. You should go through the official documentation to understand new changes and learn how you can integrate them into your application.

Let's review some of the changes in Django 4.2 that can help you in future upgrades.

First, support for MariaDB 10.3, MySQL 5.7, and PostgreSQL 11 databases was dropped. If your application was using any of these database versions, consider upgrading. Make sure to back up your data before upgrading to avoid service disruptions.

Second, Django 4.2 changed how we do data indexing. In the past, we indexed data using the statement below:

index_together = [["rank", "name"]]

But now we must call the Index method from the models class, as demonstrated below.

indexes = [models.Index(fields=["rank", "name"])]

Third, the length_is template filter is now deprecated and has instead been replaced by the traditional == operator.

Don't do this:

{% if value|length_is:4 %}{% endif %}
{{ value|length_is:4 }}

Do this:

{% if value|length == 4 %}{% endif %}
{% if value|length == 4 %}True{% else %}False{% endif %}


Updates are a normal thing during software development. Therefore, it's best to learn how to integrate them in our applications. Apart from improved security, software updates allow us to deal with bugs and ensure that our code is maintainable.

When upgrading your software, make sure to test things out in your local environment before pushing them to production. We don't want things to break and cause a poor user experience, don't we?

What to do next:
  1. Try Honeybadger for FREE
    Honeybadger helps you find and fix errors before your users can even report them. Get set up in minutes and check monitoring off your to-do list.
    Start free trial
    Easy 5-minute setup — No credit card required
  2. Get the Honeybadger newsletter
    Each month we share news, best practices, and stories from the DevOps & monitoring community—exclusively for developers like you.
    author photo

    Michael Barasa

    Michael Barasa is a software developer. He loves technical writing, contributing to open source projects, and creating learning material for aspiring software engineers.

    More articles by Michael Barasa
    Stop wasting time manually checking logs for errors!

    Try the only application health monitoring tool that allows you to track application errors, uptime, and cron jobs in one simple platform.

    • Know when critical errors occur, and which customers are affected.
    • Respond instantly when your systems go down.
    • Improve the health of your systems over time.
    • Fix problems before your customers can report them!

    As developers ourselves, we hated wasting time tracking down errors—so we built the system we always wanted.

    Honeybadger tracks everything you need and nothing you don't, creating one simple solution to keep your application running and error free so you can do what you do best—release new code. Try it free and see for yourself.

    Start free trial
    Simple 5-minute setup — No credit card required

    Learn more

    "We've looked at a lot of error management systems. Honeybadger is head and shoulders above the rest and somehow gets better with every new release."
    — Michael Smith, Cofounder & CTO of YvesBlue

    Honeybadger is trusted by top companies like:

    “Everyone is in love with Honeybadger ... the UI is spot on.”
    Molly Struve, Sr. Site Reliability Engineer, Netflix
    Start free trial
    Are you using Sentry, Rollbar, Bugsnag, or Airbrake for your monitoring? Honeybadger includes error tracking with a whole suite of amazing monitoring tools — all for probably less than you're paying now. Discover why so many companies are switching to Honeybadger here.
    Start free trial
    Stop digging through chat logs to find the bug-fix someone mentioned last month. Honeybadger's built-in issue tracker keeps discussion central to each error, so that if it pops up again you'll be able to pick up right where you left off.
    Start free trial