Core Decorators
fasthx.hx(render, *, no_data=False, render_error=None)
Decorator that converts a FastAPI route's return value into HTML if the request was an HTMX one.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
render
|
HTMLRenderer[T]
|
The render function converting the route's return value to HTML. |
required |
no_data
|
bool
|
If set, the route will only accept HTMX requests. |
False
|
render_error
|
HTMLRenderer[Exception] | None
|
Optional render function for handling exceptions raised by the decorated route.
If not |
None
|
Returns:
Type | Description |
---|---|
Callable[[MaybeAsyncFunc[P, T]], Callable[P, Coroutine[None, None, T | Response]]]
|
The rendered HTML for HTMX requests, otherwise the route's unchanged return value. |
Source code in fasthx/core_decorators.py
fasthx.page(render, *, render_error=None)
Decorator that converts a FastAPI route's return value into HTML.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
render
|
HTMLRenderer[T]
|
The render function converting the route's return value to HTML. |
required |
render_error
|
HTMLRenderer[Exception] | None
|
Optional render function for handling exceptions raised by the decorated route.
If not |
None
|