From fc0fa72ff4cdbf5861a366e31cb8bbacd44da22d Mon Sep 17 00:00:00 2001 From: Andrew Godwin Date: Wed, 12 Feb 2020 15:15:00 -0700 Subject: Fixed #31224 -- Added support for asynchronous views and middleware. This implements support for asynchronous views, asynchronous tests, asynchronous middleware, and an asynchronous test client. --- docs/releases/3.1.txt | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) (limited to 'docs/releases') diff --git a/docs/releases/3.1.txt b/docs/releases/3.1.txt index 642575d023..efc57e8d01 100644 --- a/docs/releases/3.1.txt +++ b/docs/releases/3.1.txt @@ -27,6 +27,43 @@ officially support the latest release of each series. What's new in Django 3.1 ======================== +Asynchronous views and middleware support +----------------------------------------- + +Django now supports a fully asynchronous request path, including: + +* :ref:`Asynchronous views ` +* :ref:`Asynchronous middleware ` +* :ref:`Asynchronous tests and test client ` + +To get started with async views, you need to declare a view using +``async def``:: + + async def my_view(request): + await asyncio.sleep(0.5) + return HttpResponse('Hello, async world!') + +All asynchronous features are supported whether you are running under WSGI or +ASGI mode. However, there will be performance penalties using async code in +WSGI mode. You can read more about the specifics in :doc:`/topics/async` +documentation. + +You are free to mix async and sync views, middleware, and tests as much as you +want. Django will ensure that you always end up with the right execution +context. We expect most projects will keep the majority of their views +synchronous, and only have a select few running in async mode - but it is +entirely your choice. + +Django's ORM, cache layer, and other pieces of code that do long-running +network calls do not yet support async access. We expect to add support for +them in upcoming releases. Async views are ideal, however, if you are doing a +lot of API or HTTP calls inside your view, you can now natively do all those +HTTP calls in parallel to considerably speed up your view's execution. + +Asynchronous support should be entirely backwards-compatible and we have tried +to ensure that it has no speed regressions for your existing, synchronous code. +It should have no noticeable effect on any existing Django projects. + Minor features -------------- -- cgit v1.3