... ost (see パフォーマンス ), and without the ability to have efficient long-running requests. Many parts of Django provide asynchronous APIs, including the ORM , the cache framework, authentication, sessions, and signals. For other code, the sync_to_a ... sync() adapter is a low-cost bridge (see パフォーマンス ). A wide range of async-native Python libraries can also be integrated. 非同期ビュー どのようなビューでも、呼び出し可能オブジェクトでコルーチンを返 ... すようにすれば、非同期として宣言できます。その際には、一般的に async def を使います。関数ベースのビューの場合、 async def を用いてビュー全体を宣言します。クラスベースのビューの場合、 get() と ... ... ording to the backend, InvalidTask is raised. See enqueueing Tasks for usage examples. aenqueue ( * args , ** kwargs ) The async variant of enqueue . get_result ( result_id ) [ソース] Retrieves a result by its id. If the result does not exist, TaskRes ... ised. If the backend does not support get_result() , NotImplementedError is raised. aget_result ( * args , ** kwargs ) The async variant of get_result . Task context class TaskContext [ソース] Contains context for the running Task . Context only passe ... eturn values for usage examples. refresh () [ソース] Refresh the result's attributes from the queue store. arefresh () The async variant of TaskResult.refresh() . is_finished [ソース] Whether the Task has finished (successfully or not). attempts [ソー ... ... グ関数は一致する必要があります。ミドルウェアがこの種のイテレータをサポートする必要がある場合には、 StreamingHttpResponse.is_async 確認してください。 例外のハンドリング Django はビューまたはミドルウェアによって起こされた例外を、エラーステータスコードを持 ... 属性を設定します。 sync_capable は、ミドルウェアが同期リクエストを処理できるかどうかを表すブール値です。デフォルトは True 。 async_capable は、ミドルウェアが非同期リクエストを処理できるかどうかを表すブール値です。デフォルトは False 。 If your middleware ... has both sync_capable = True and async_capable = True , then Django will pass it the request without converting it. In this case, you can work out if your middle ... ... 引数が追加される可能性があり、レシーバはその新しい引数を扱えなければならないからです。 レシーバーは同じシグネチャーを持ち、 async def を使って宣言された非同期関数になることもできます: async def my_receiver ( sender , ** kwargs ): await asyncio . sleep ... 返されるエラーの __traceback__ 属性に存在します。 asend() は send() と似ていますが、await しなければならないコルーチンです: async def asend_pizza ( self , toppings , size ): await pizza_done . asend ( sender = self . __class__ , toppings = toppings , s ... ize = size ) ... Whether synchronous or asynchronous, receivers will be correctly adapted to whether send() or asend() is used. Synchronous receivers will be called usi ... ... )。各バージョン系列の最新リリースのみを公式にサポートし、最新リリースを使用することを 強く推奨 します。 Django 3.1 の新機能 Asynchronous views and middleware support Django now supports a fully asynchronous request path, including: Asynchronous views A ... synchronous middleware Asynchronous tests and test client To get started with async views, you need to declare a view using async def : async def my_vi ... ew ( request ): await asyncio . sleep ( 0.5 ) return HttpResponse ( "Hello, async world!" ) All asynchronous features are supported whether you are ru ... ... 非同期のクラスベース・ビュー 既に示した同期 ( def ) メソッドハンドラと同様に、 View サブクラスは await : を使用して非同期 ( async def ) メソッドハンドラを定義できます: import asyncio from django.http import HttpResponse from django.views import View cl ... ass AsyncView ( View ): async def get ( self , request , * args , ** kwargs ): # Perform io-blocking view logic using await, sleep f ... or example. await asyncio . sleep ( 1 ) return HttpResponse ( "Hello async world!" ) 1つのビュークラス内では、すべてのユーザー定義メソッドハンドラ ... ... nd the code in the django/tasks/backends/ directory of the Django source. 非同期サポート Django has developing support for asynchronous Task backends. BaseTaskBackend has async variants of all base methods. By convention, the asynchronous versions of ... a TaskResult , which can be used to retrieve the result of the Task once it has finished executing. To enqueue Tasks in an async context, aenqueue() is available as an async variant of enqueue() . Because both Task arguments and return values are seri ... jango.tasks import default_task_backend result = default_task_backend . get_result ( result_id ) To retrieve results in an async context, aget_result() is available as an async variant of get_result() on both the backend and Task . Some backends, such ... ... ixed a regression in Django 3.0 by restoring the ability to use Django inside Jupyter and other environments that force an async context, by adding an option to disable 非同期安全性 mechanism with DJANGO_ALLOW_ASYNC_UNSAFE environment variable ( #3105 ... ... or inequality assertJSONEqual() JSON fragment equality 編集した設定 でテストを実行する機能。 Access to the synchronous and asynchronous test clients via the client and async_client attributes. データベースクエリを作る手薄との場合、サブクラス Transacti ... ocumentation を参照してください。 テストケースの機能 デフォルトのテストクライアント SimpleTestCase. client SimpleTestCase. async_client Every django.test.*TestCase instance has access to Django's synchronous and asynchronous test clients as self.clien ... t and self.async_client , respectively. Both clients are recreated for each test, so you don't have to worry about state (such as cookies) ... ... ) ( #31877 ). Enforced thread sensitivity of the MiddlewareMixin.process_request() and process_response() hooks when in an async context ( #31905 ). Fixed __in lookup on key transforms for JSONField with MariaDB, MySQL, Oracle, and SQLite ( #31936 ). ... user didn't have permissions to all intermediate directories in a Django installation path ( #31912 ). Fixed detecting an async get_response callable in various builtin middlewares ( #31928 ). Fixed a QuerySet.order_by() crash on PostgreSQL when orde ... 2026年10月08日