Django 4.1 Released!

Gustav Willig
2 min readAug 6, 2022

--

Own creation, background image from https://unsplash.com/photos/npxXWgQ33ZQ

On August 3, 2022, Django 4.1 was just published, and in this article, we’ll go over the top five key improvements and new features.

1. Asynchronous handlers for class-based views

View subclasses may now define async HTTP method handlers:

import asyncio
from django.http import HttpResponse
from django.views import View
class AsyncView(View):
async def get(self, request, *args, **kwargs):
# Perform view logic using await.
await asyncio.sleep(1)
return HttpResponse("Hello async world!")

See Asynchronous class-based views for more details.

2. Asynchronous ORM interface

QuerySet now provides an asynchronous interface for all data access operations. These are named as-per the existing synchronous operations but with an a prefix, for example acreate(), aget(), and so on.

The new interface allows you to write asynchronous code without needing to wrap ORM operations in sync_to_async():

async for author in Author.objects.filter(name__startswith="A"):
book = await author.books.afirst()

Note that, at this stage, the underlying database operations remain synchronous, with contributions ongoing to push asynchronous support down into the SQL compiler, and integrate asynchronous database drivers. The new asynchronous queryset interface currently encapsulates the necessary sync_to_async() operations for you, and will allow your code to take advantage of developments in the ORM’s asynchronous support as it evolves.

See Asynchronous queries for details and limitations.

3. Requests and Responses

4. django.contrib.gis

5. django.contrib.postgres

More information can be found here.

Happy Coding!

--

--

Gustav Willig
Gustav Willig

Written by Gustav Willig

An AI Full-Stack Developer with a passion for using data to drive business decisions. Get your latest news about Django and AI trends by subscribing

No responses yet