Skip to content

Base

AsyncView

async CBVs are supported via the AsyncView class.

from django_async_extensions.views.generic import AsyncView


class MyView(AsyncView):
    pass

the AsyncView works similar to django's View class, with a few differences:

  1. AsyncView.as_view() returns a coroutine.
  2. AsyncView.dispatch() is an async function.
  3. http handlers (def get(), def post()) are expected to be async.

AsyncTemplateView

for easy use an async version of TemplateView is available

from django_async_extensions.views.generic import AsyncTemplateView

class MyTemplateView(AsyncTemplateView):
    template_name = "template.html"

AsyncTemplateView works like django's TemplateView except the inheritance tree is different, also the get() method is async.

Ancestors (MRO):

  1. django_async_extensions.views.generic.base.AsyncTemplateResponseMixin
  2. django.views.generic.base.TemplateResponseMixin
  3. django_async_extensions.views.generic.base.AsyncContextMixin
  4. django_async_extensions.views.generic.base.AsyncView
  5. django.views.generic.base.View

AsyncRedirectView

an async version of RedirectView is also available

from django_async_extensions.views.generic import AsyncRedirectView

class ThisRedirectView(AsyncRedirectView):
    pattern_name = "that-view"

AsyncRedirectView works like django's RedirectView except that all http methods are async, and it inherits from AsyncView.

Ancestors (MRO):

  1. django_async_extensions.views.generic.base.AsyncView
  2. django.views.generic.base.RedirectView
  3. django.views.generic.base.View