Hx Tags
hx_get and hx_post are template tags for setting up HxRequests.
They function identically, except hx_get makes a GET request, while hx_post makes a POST request.
Parameters
HxRequestName (required) – The name of the HxRequest being used.Object (optional) - If provided, this object is associated with the
HxRequest(similar to Django’s UpdateView )use_full_path (optional) - If set to True, the full path of the
urlis used. See How To Add GET Parameters To POST RequestsKeyword Arguments (
kwargs) - Additional arguments passed into theHxRequest. These can be DjangoModelobjects because they are serialized.
Behavior
- If an object is passed in:
It is added as
hx_objectinside the HxRequest and accessible asself.hx_object.If
hx_object_nameis not set on theHxRequest, the object is available in the template ashx_object, accessible with{{ hx_object }}.If
hx_object_nameis set, the object is available in the template as whathx_object_nameis set to.
- Kwargs
Accessible in the
HxRequestthrough**kwargsin each method.Available in the template as context variables, unless
kwargs_as_context = Falseis set on theHxRequest, in which case they are stored inhx_kwargs, accessible as {{ hx_kwargs.key }}.
kwargsare serialized (see Handling kwargs Serialization) and carried inside the signed token, not as loose query parameters.
Example
<button {% hx_get 'my_hx_request' object=my_instance %}></button>
Is equal to:
<button hx-get="my-website/current-page?hx=<signed-token>"></button>
The hx parameter is a single HMAC-signed token that packs the
HxRequest name, the serialized object, and any serialized kwargs. The
client can read the token but cannot forge or tamper with it without the
project’s SECRET_KEY, so the name/object/kwargs are trusted framework
data rather than editable query params.
Note
See Object Serialization for more information on how objects and kwargs are serialized and packed into the token.
hx_url
hx_url takes the same arguments as hx_get / hx_post but
returns only the signed URL (the value of the hx query string), not a
full hx-get=".." attribute. Use it when you need to build the request
attribute yourself – for example on a non-button element, with a different
htmx verb, or inside hx-vals / JavaScript.
<div hx-get="{% hx_url 'my_hx_request' object=my_instance %}" hx-trigger="revealed"></div>