htmx 4.0 is under construction — migration guide

HX-Target

The element that will receive the response

The HX-Target request header identifies the element that will receive the response.

This header is only included when a target is specified.

Format: <tag>#<id> (e.g. div#results) or just <tag> for elements without an ID.

Syntax

The header is included as follows:

HX-Target: div#results

Usage

Return different content for different targets:

target = request.headers.get('HX-Target') if target == 'div#sidebar': return render_template('sidebar_content.html')