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:
AsyncView.as_view()returns a coroutine.AsyncView.dispatch()is an async function.- 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):
- django_async_extensions.views.generic.base.AsyncTemplateResponseMixin
- django.views.generic.base.TemplateResponseMixin
- django_async_extensions.views.generic.base.AsyncContextMixin
- django_async_extensions.views.generic.base.AsyncView
- 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):