Django upgrade from version 2.1 to version 4

Hello. I got thrown into the fire with an application that haven’t been updated in a while. I’ve been tasked to update it. I honestly tried following the docs with upgrading these major versions and it seems like I’ve done something wrong. Here’s the error message that I’m receiving:

Error Message:
Traceback (most recent call last):
File “/Users/joshuacovington/Desktop/Git/Beekeeper/env/lib/python3.9/site-packages/django/template/backends/django.py”, line 128, in get_package_libraries
module = import_module(entry[1])
File “/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/importlib/init.py”, line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File “”, line 1030, in _gcd_import
File “”, line 1007, in _find_and_load
File “”, line 986, in _find_and_load_unlocked
File “”, line 680, in _load_unlocked
File “”, line 850, in exec_module
File “”, line 228, in _call_with_frames_removed
File “/Users/joshuacovington/Desktop/Git/Beekeeper/env/lib/python3.9/site-packages/django_extensions/templatetags/widont.py”, line 6, in
from django.utils.encoding import force_text
ImportError: cannot import name ‘force_text’ from ‘django.utils.encoding’ (/Users/joshuacovington/Desktop/Git/Beekeeper/env/lib/python3.9/site-packages/django/utils/encoding.py)

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File “/Users/joshuacovington/Desktop/Git/Beekeeper/manage.py”, line 21, in
main()
File “/Users/joshuacovington/Desktop/Git/Beekeeper/manage.py”, line 17, in main
execute_from_command_line(sys.argv)
File “/Users/joshuacovington/Desktop/Git/Beekeeper/env/lib/python3.9/site-packages/django/core/management/init.py”, line 442, in execute_from_command_line
utility.execute()
File “/Users/joshuacovington/Desktop/Git/Beekeeper/env/lib/python3.9/site-packages/django/core/management/init.py”, line 436, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File “/Users/joshuacovington/Desktop/Git/Beekeeper/env/lib/python3.9/site-packages/django/core/management/base.py”, line 412, in run_from_argv
self.execute(*args, **cmd_options)
File “/Users/joshuacovington/Desktop/Git/Beekeeper/env/lib/python3.9/site-packages/django/core/management/base.py”, line 458, in execute
output = self.handle(*args, **options)
File “/Users/joshuacovington/Desktop/Git/Beekeeper/env/lib/python3.9/site-packages/django/core/management/base.py”, line 106, in wrapper
res = handle_func(*args, **kwargs)
File “/Users/joshuacovington/Desktop/Git/Beekeeper/env/lib/python3.9/site-packages/django/core/management/commands/migrate.py”, line 100, in handle
self.check(databases=[database])
File “/Users/joshuacovington/Desktop/Git/Beekeeper/env/lib/python3.9/site-packages/django/core/management/base.py”, line 485, in check
all_issues = checks.run_checks(
File “/Users/joshuacovington/Desktop/Git/Beekeeper/env/lib/python3.9/site-packages/django/core/checks/registry.py”, line 88, in run_checks
new_errors = check(app_configs=app_configs, databases=databases)
File “/Users/joshuacovington/Desktop/Git/Beekeeper/env/lib/python3.9/site-packages/django/core/checks/templates.py”, line 60, in check_for_template_tags_with_the_same_name
for module_name, module_path in get_template_tag_modules():
File “/Users/joshuacovington/Desktop/Git/Beekeeper/env/lib/python3.9/site-packages/django/template/backends/django.py”, line 105, in get_template_tag_modules
for name in get_package_libraries(pkg):
File “/Users/joshuacovington/Desktop/Git/Beekeeper/env/lib/python3.9/site-packages/django/template/backends/django.py”, line 130, in get_package_libraries
raise InvalidTemplateLibrary(
django.template.library.InvalidTemplateLibrary: Invalid template library specified. ImportError raised when trying to load ‘django_extensions.templatetags.widont’: cannot import name ‘force_text’ from ‘django.utils.encoding’ (/Users/joshuacovington/Desktop/Git/Beekeeper/env/lib/python3.9/site-packages/django/utils/encoding.py)

Could I please get some help with this. In other files I went in and changed the import. For some reason I can’t find this import even when I navigate to this file. Is there a script or something I can run to ensure I upgrade my dependencies that match with this current version.

What step of the process are you on? (It’s going to be a lot of work to go from 2.1 directly to 4. You should have at least two or three intermediate steps along the way.)

Some of this is due to the different versions of Python supported. Django 2.1 only supports 3.5, 3.6 and 3.7. (See Django 2.1 release notes | Django documentation | Django)

It looks like you’re using Python 3.9, which isn’t supported until Django 2.2.17. (Django 2.2 release notes | Django documentation | Django)

Hello. Thank you for replying back to me. I’ve unfortunately lost in which step I’m in. I don’t think I’ll be able to start over or down grade to a lower version and then work my way back up. Django is now up to date, but I’m having issues regarding the dependencies is what I’m gathering. When I try to make a migration it gets far within the process, but I keep getting the error that’s in the question above. I’ve done a lot of searching and updating, but it does not seem to do the trick.

Ok, let me rephrase my question this way.

Right now, as you’re trying to run this project, what version of Django and Python are you using?

Right now I’m running Django version 4 and python version 3.12

You should be reviewing all of the Release Notes for all versions between what you were using and what you’re using now.

In this specific case, the error from above is:

See https://docs.djangoproject.com/en/5.0/releases/3.0/#features-deprecated-in-3-0 and https://docs.djangoproject.com/en/5.0/releases/4.0/#features-removed-in-4-0 regarding force_text.