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

  • HxRequest Name (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 url is used. See How To Add GET Parameters To POST Requests

  • Keyword Arguments (kwargs) - Additional arguments passed into the HxRequest. These can be Django Model objects because they are serialized.

Behavior

  • If an object is passed in:
    • It is added as hx_object inside the HxRequest and accessible as self.hx_object.

    • If hx_object_name is not set on the HxRequest, the object is available in the template as hx_object, accessible with {{ hx_object }}.

    • If hx_object_name is set, the object is available in the template as what hx_object_name is set to.

  • Kwargs
    • Accessible in the HxRequest through **kwargs in each method.

    • Available in the template as context variables, unless kwargs_as_context = False is set on the HxRequest, in which case they are stored in hx_kwargs, accessible as {{ hx_kwargs.key }}.

    • kwargs are 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.

`