Unlock the Power of Django v4.0: New Features and Deprecations
Get Ready for a Smoother Upgrade
In December 2021, the Django team rolled out Django v4.0, packed with exciting upgrades and improvements. However, it’s essential to note that only Python versions 3.8, 3.9, and 3.10 will support this latest release. Before diving into the new features, make sure to resolve any deprecation warnings in your current Django version.
Enable Deprecation Warnings
By default, deprecation warnings are turned off. To enable them, use the following test command:
Install Django v4.0
Once you’ve fixed any deprecation warnings, you can upgrade to Django v4.0 using pip with the --upgrade
or -U
flag:
Dropped Support for Older Packages
With the introduction of Django v4.0, some lower third-party package versions will no longer be supported. Here’s a list of the affected packages:
- PostgreSQL v9.6 and earlier
- Oracle v12.2 and 18c
- PostGIS 2.3
- GDAL 2.0 and GEOS 3.5
- cx_ORACLE 7.0
- The
django.utils.text.unescape_entities()
function - The
django.utils.http.is_safe_url()
function
What’s New in Django v4.0?
zoneinfo Default Time Zone
Django v4.0 has migrated to the zoneinfo
time zone, deprecating support for the pytz
time zone. This change is relatively straightforward, and you can easily select the current time zone and convert datetime instances in forms and templates.
Template-Based Form Rendering
Forms, Formsets, and ErrorList are now rendered using the template engine, enhancing customization. The render()
options are now optional, with None
being the default value for all of them.
Internationalization and Localization
Django v4.0 now supports Malay language translations, and the default value of the USE_L10N
parameter has been changed to True
. Additionally, the CSRF_TRUSTED_ORIGINS
setting has been updated to require the scheme (e.g., http://
or https://
) and values starting with a dot must be preceded by an asterisk.
Scrypt Password Hasher
The scrypt
password hasher has been added to provide additional security. It’s recommended to use scrypt
instead of PBKDF2
to limit parallelism attacks.
Functional Unique Constraints
The UniqueConstraint()
now has a new expressions
positional option, allowing programmers to implement functional unique constraints with the same database restrictions as Index.expressions
.
Get Started with LogRocket
Take your development to the next level with LogRocket’s modern error tracking. Sign up for a free trial and get started in minutes!