... 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() と ... ... グ関数は一致する必要があります。ミドルウェアがこの種のイテレータをサポートする必要がある場合には、 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 ca ... ... 引数が追加される可能性があり、レシーバはその新しい引数を扱えなければならないからです。 レシーバーは同じシグネチャーを持ち、 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 wi ... ... ードを変更している場合、ソケットがクリーンに閉じられるように、中断されたリクエストに遭遇した際にはこれを発生させるべきです。 SynchronousOnlyOperation exception SynchronousOnlyOperation [ソース] SynchronousOnlyOperation 例外は、同期的な Python コードでの ... スレッドから同期専用のコードを呼び出そうとしている場合は、同期スレッドを作成し、その中で呼び出してください。これは、 asgiref.sync.sync_to_async() を使用して実現できます。 URL Resolver の例外 URL Resolver の例外は django.urls で定義されています。 Resolv ... ... where alogin() and alogout() did not respectively set or clear request.user if it had already been materialized (e.g., by sync middleware) ( #37017 ). Fixed a regression in Django 6.0 in admin forms where RelatedFieldWidgetWrapper incorrectly wrappe ... ... ス・ビューにおける非同期ハンドラ ビューのサブクラスで、非同期の HTTP メソッドハンドラーを定義できるようになりました: import asyncio from django.http import HttpResponse from django.views import View class AsyncView ( View ): async def get ( self , requ ... est , * args , ** kwargs ): # Perform view logic using await. await asyncio . sleep ( 1 ) return HttpResponse ( "Hello async world!" ) 詳細は 非同期のクラスベース・ビュー を参照してください。 非同 ... 期の ORM インターフェース QuerySet now provides an asynchronous interface for all data access operations. These are named as-per the existing synchronous operations but with an a ... ... ... agment equality or inequality assertJSONEqual() JSON fragment equality 編集した設定 でテストを実行する機能。 Access to the synchronous and asynchronous test clients via the client and async_client attributes. データベースクエリを作る手薄との場合、サブ ... cumentation を参照してください。 テストケースの機能 デフォルトのテストクライアント 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) ... ... す: cache_page = decorator_from_middleware_with_args ( CacheMiddleware ) @cache_page ( 3600 ) def my_view ( request ): pass sync_only_middleware ( middleware ) [ソース] ミドルウェアを 同期専用 としてマークします。(これはDjangoのデフォルトですが、将来的 ... にデフォルトが変更された場合に備えて、あらかじめ設定しておくことを可能にします。) async_only_middleware ( middleware ) [ソース] ミドルウェアを 非同期専用 としてマークします。WSGIリクエストパスから呼び出されたと ... き、Djangoはそれを非同期イベントループでラップします。 sync_and_async_middleware ( middleware ) [ソース] ミドルウェアを 同期および非同期互換 としてマークすることで、リクエストの変換を ... ... 。各バージョン系列の最新リリースのみを公式にサポートし、最新リリースを使用することを 強く推奨 します。 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 ... 2026年10月08日