An async view is a Django request handler implemented as an asynchronous callable. It can suspend at await points while asynchronous operations run, making it useful for requests to external APIs. section 9.4
Django’s ASGI support enables async views, while its WSGI support remains available. Async support is still evolving, and the ORM is synchronous, so blocking work requires care. section 9.4
Aggregating concurrent HTTP requests
An async view can use aiohttp to create a client session, build several request coroutines, await them with asyncio.gather, collect exceptions, and render response status, timing, and body length in a table.
Handle synchronous operations explicitly:
- Wrap blocking functions with asgiref.sync.sync_to_async and await the resulting callable. section 9.4.1
- Keep thread_sensitive=True when shared state depends on a specific thread; otherwise, False can use separate threads and avoid blocking Django’s main thread. section 9.4.1
