Allow View subclasses to define async method handlers.
The current topic docs for Async views say this about class-based views:
For a class-based view, this means making its __call__() method an async def (not its __init__() or as_view()).
This isn't really appropriate for Django's class-based views:
- We don't implement
__call__(), rather going via as_view() — for a per-request instance — and then dispatch().
- Users expect to implement the HTTP method handlers —
get(), post(), and so on — rather than these more internal bits.
Ideally we'd allow specifying async def at the method handler level, to allow using await in the handler, and writing views such as this:
import asyncio
from django.http import HttpResponse
from django.views import View
class AsyncView(View):
async def get(self, request, *args, **kwargs):
# Perform io-blocking view-logic using await, sleep for example.
await asyncio.sleep(1)
return HttpResponse("Hello async world!")
Change History
(8)
| Component: |
HTTP handling → Generic views
|
| Description: |
modified (diff)
|
| Triage Stage: |
Unreviewed → Accepted
|
| Owner: |
changed from nobody to Carlton Gibson
|
| Patch needs improvement: |
set
|
| Patch needs improvement: |
unset
|
| Triage Stage: |
Accepted → Ready for checkin
|
| Resolution: |
→ fixed
|
| Status: |
assigned → closed
|
PR