HTMX Enhanced Responses

flask_htmx.responses.make_response(*args: Any, location: str | dict | None = None, push_url: str | False | None = None, redirect: str | None = None, refresh: bool = False, replace_url: str | False | None = None, reswap: str | None = None, retarget: str | None = None, trigger: str | dict | None = None, trigger_after_settle: str | dict | None = None, trigger_after_swap: str | dict | None = None) Response[source]

This function can be used as a replacement from flask.make_response to easily add htmx response headers to the request.

See https://htmx.org/reference/#response_headers for more details about the headers.

Parameters
  • args – Arguments you would normally use with flask.make_response.

  • location – Allows you to do a client-side redirect that does not do a full page reload. Accepts a string or a dict (HX-Location).

  • push_url – Pushes a new url into the history stack. Accepts a string—the URL to be pushed into the location bar—or False—prevents the browser’s history from being updated—(HX-Push-URL).

  • redirect – Can be used to do a client-side redirect to a new location (HX-Redirect).

  • refresh – If set to True the client side will do a full refresh of the page (HX-Refresh).

  • replace_url – Replaces the current URL in the location bar. Accepts a string—the URL to replace the current URL in the location bar—or :py:obj:False:—prevents the browser’s current URL from being updated—(HX-Replace-URL).

  • reswap – Allows you to specify how the response will be swapped. Possible values: “innerHTML”, “outerHTML”, “beforebegin” “afterbegin”, “beforeend”, “afterend”, “delete”, “none”. Notice None means to not send the header, which is different from “none” (HX-Reswap).

  • retarget – A CSS selector that updates the target of the content update to a different element on the page (HX-Retarget).

  • trigger – Allows you to trigger client side events. Accepts a string or a dict (HX-Trigger).

  • trigger_after_settle – Allows you to trigger client side events. Accepts a string or a dict (HT-Trigger-After-Settle).

  • trigger_after_swap – Allows you to trigger client side events. Accepts a string or a dict (HT-Trigger-After-Swap).

Returns

A Flask Response with htmx headers.