Correct way to use async class based views in Django Correct way to use async class based views in Django django django

Correct way to use async class based views in Django


Spend quite some time searching in the Django ticket system, blogposts (thx to Joren), etc. so you don't have to.

The best you can do is using the code from the blog:

class YourView(View):    @classonlymethoddef as_view(cls, **initkwargs):    view = super().as_view(**initkwargs)    view._is_coroutine = asyncio.coroutines._is_coroutine    return viewasync def get(self, *args, **kwargs):    ...

But you also need to be aware there is no way you can use actual generics (no async ORM support, even TemplateView doesn't work) and build-in decorators for 3.1. You need to write your own stuff for things that Django normally does itself.