[docs]classHtmxMiddleware:sync_capable=Trueasync_capable=Truedef__init__(self,get_response:(Callable[[HttpRequest],HttpResponseBase]|Callable[[HttpRequest],Awaitable[HttpResponseBase]]),)->None:self.get_response=get_responseself.async_mode=iscoroutinefunction(self.get_response)ifself.async_mode:# Mark the class as async-capable, but do the actual switch# inside __call__ to avoid swapping out dunder methodsmarkcoroutinefunction(self)def__call__(self,request:HttpRequest)->HttpResponseBase|Awaitable[HttpResponseBase]:ifself.async_mode:returnself.__acall__(request)request.htmx=HtmxDetails(request)# type: ignore [attr-defined]returnself.get_response(request)asyncdef__acall__(self,request:HttpRequest)->HttpResponseBase:request.htmx=HtmxDetails(request)# type: ignore [attr-defined]returnawaitself.get_response(request)# type: ignore [no-any-return, misc]