I'm using Django, Is there a way to check if the current request is from HTMX
CodePudding user response:
Regardless of the server-side solution you use, you can look for the HX-Request
header. It will be set to true
in all htmx requests. More information can be found here https://htmx.org/docs/#request-header
CodePudding user response:
Yes you can by using HTTP_HX_REQUEST
of request.META
like this:
if request.META.get('HTTP_HX_REQUEST'):
print("HTMX is available")
else:
print("HTMX is not available")
CodePudding user response:
You can check for HX-Request
in the request headers, as mentioned in another answer. Or you can use the HTMX Django extension and simply check if request.htmx
is True
.