Django and HTMX I am looking for not "hacky" way to update class of link that calls HTMX request. Like "refresh-self" or something along those lines

Solution 1:

The easiest way to avoid this issue is to detect the HTMX request in the view function, pass this state to your templates and render HTMX content only if needed. HTMX will add a HX-Request: true header to each request.

For the detection you can use the Django-HTMX package that provides a request.htmx variable in your view functions that will be True if the request is coming from HTMX. Or if you want to check it manually:

def my_view(request):
    is_htmx = request.headers.get('HX-Request') == 'true'
    return render(request, 'my_template.html', {'is_htmx': is_htmx})

After that in manual_entries_list.html template include HTMX related stuff only in the HTMX requests:

<some html results>
{% if is_htmx %}
<div id="manual_categories" hx-swap-oob="true">
  {% include 'partials/manual_categories.html' %}
</div>
{% endif %}