#33611: Allow View subclasses to define async method handlers.
-------------------------------------+-------------------------------------
               Reporter:  Carlton    |          Owner:  nobody
  Gibson                             |
                   Type:  New        |         Status:  assigned
  feature                            |
              Component:  HTTP       |        Version:  4.0
  handling                           |
               Severity:  Normal     |       Keywords:  async, asgi, views
           Triage Stage:             |      Has patch:  1
  Unreviewed                         |
    Needs documentation:  0          |    Needs tests:  0
Patch needs improvement:  0          |  Easy pickings:  0
                  UI/UX:  0          |
-------------------------------------+-------------------------------------
 The current [https://docs.djangoproject.com/en/4.0/topics/async/#async-
 views 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!")
 }}}

-- 
Ticket URL: <https://code.djangoproject.com/ticket/33611>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-updates+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/0107017fdec7b7db-c6341929-4bcf-475c-b025-6363ac973654-000000%40eu-central-1.amazonses.com.

Reply via email to