HX Tags

There are two template tags to use to setup HXRequests: hx_get and hx_post. They are identical except that one makes a get request and one makes a post request.

hx_get

Example from quickstart

{% load hx_tags %}
<div id="user_info_target"></div>
<button {% hx_get 'get_user_info' %}
        hx-target="#user_info_target"
        type="button">
    Click Me
</button>
  • hx_get takes in:
    • The name of the HXRequest that is being used

    • An object if there is one that is associted with the HXRequest (similar to Django’s UpdateView )

    • And kwargs

Notes:
  • If an object is passed in it is added as an attribute to the HXRequest as hx_object and can be accessed as self.hx_object

  • If hx_object_name is not set on the HXRequest, the object is passed into the template (GET_template for get requests or POST_template for post requests) as hx_object and can be accessed in the template as {{ hx_object }}

  • Kwargs that are passed in are accessible in the HXRequest (through **kwargs in each method). They get passed into the template as part of the context, unless kwargs_as_context is set to False then they are put in as hx_kwargs and can be accessed as {{ hx_kwargs.key }}

  • Besides for primitive types the object and the kwargs can be a model_instance (an instance of a Django model) because a model_instance gets serialized by hx_get.

Warning

Objects passed into hx_get, whether as the ‘object’ or in kwargs must be Django model_instance. Other objects will not be serialized/ deserialized (primitives are of course okay).

hx_post

Same as above except that a post request will be made instead of a get request.