Django 4.0 Adam Johnson

New Testing Features in Django 4.0

Django 4.0’s five headline features

#1 zoneinfo as the default timezone implementation

Django historically relied on pytz for timezones, but it has… issues. contributed zoneinfo to Python’s standard library, to address these. Django now uses zoneinfo.

Thanks to for contributing this.


In [6]: import zoneinfo
In [7]: zoneinfo.ZoneInfo("Europe/Paris")
Out[7]: zoneinfo.ZoneInfo(key='Europe/Paris')


In [8]: import pytz
In [9]: pytz.timezone("Europe/Paris")
Out[9]: <DstTzInfo 'Europe/Paris' LMT+0:09:00 STD>

#2 Functional unique constraints

You can now use database functions to define unique constraints. This allows you to enforce uniqueness on transformed values, e.g. to ensure email addresses unique despite use of upper/lower case

Thanks to for contributing this.

class Person(models.Model):

class Meta:
    constraints = [
           name ="%(app_label)s_%(class)s_unique_email",

#3 scrypt password hasher

Django defaults to using PBKDF2 ( ) for password hashing.

Scrypt ( ) is a stronger choice that requires more memory, to slow down attacks.

Django now includes a scrypt hasher .

Thanks to :ref`Anthony Wright < >`) for contributing this


#4 Built-in Redis cache backend is very popular with Django developers. Previously it was mainly used via the django-redis package, but now it’s built-in!

Thanks to for contributing this as a Google of Summer of Code project.

    "default": {
        "BACKEND": "django.core.cache.backends.redis.RedisCache",
        "LOCATION": "redis://",

Big congratulations to for his successful GSoC project adding a Redis cache backend to Django. Coming to you in Django 4.0. 🎁🎉



#5 Template-based form rendering

Django already rendered changed to render form widgets through templates.

Now the remaining pieces of the form process go through templates, which you can replace with custom display logic.

Thanks to and .