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 prefixed with___to differentiate them from standard query parameters (see Handling kwargs Serialization).
Example
<button {% hx_get 'my_hx_request' object=my_instance %}></button>
Is equal to:
<button hx-get="my-website/current-page?hx_request_name=my_hx_request&object=model_instance__app_name__model__id_of_my_instance"></button>
Note
See Object Serialization for more information on how objects are serialized.