API Reference
View Mixins
View Decorators
Middleware
- django_htmx_tools.middleware.htmx.htmx_auth_middleware(get_response)[source]
Middleware to handle HTMX authentication redirects.
When an HTMX request receives a 302 redirect to a login page, this middleware converts it to a 204 response with an HX-Redirect header. This ensures HTMX properly handles the redirect on the client side, preserving the original request path in the ‘next’ query parameter.
Reference: https://www.caktusgroup.com/blog/2022/11/11/how-handle-django-login-redirects-htmx/
- Parameters:
get_response – The next middleware or view in the chain.
- Returns:
A middleware function that processes HTMX authentication redirects.
- django_htmx_tools.middleware.htmx.htmx_vary_middleware(get_response)[source]
Middleware to add Vary headers for HTMX requests.
Adds ‘HX-Request’ to the Vary header for HTMX requests. Required if the server renders the full HTML when the HX-Request header is missing/ false, but renders a fragment of that HTML when HX-Request is true.
Reference: https://htmx.org/docs/#caching
- Parameters:
get_response – The next middleware or view in the chain.
- Returns:
A middleware function that patches Vary headers for HTMX requests.