Actions Reference
Detailed arguments and supported return shapes for action items and action methods.
This page focuses on the practical details. Use the quick links below to move to the previous, next, or related docs.
@action
Import:
from hyperdjango.actions import action
Usage forms:
@action
def save(self, request):
...
@action("save_profile")
def save(self, request):
...
Behavior:
- marks the method as an action
- stores the action name used by the runtime
- the action becomes discoverable through
get_action(name)
Actions(*items)
Import:
from hyperdjango.actions import Actions
Purpose:
- wrapper around multiple typed action items
Arguments:
*items: ActionItem
Notes:
- iterable at runtime
- functionally equivalent to returning a list of action items
Return Shapes
Recommended:
- list of action items
- generator yielding action items
Supported by the current runtime:
- single action item
Actions(...)strdictHttpResponse
Recommended guidance:
- use a list when the whole response is known immediately
- use a generator when the response should stream over time
- use typed action items for clarity
Dispatch compatibility details:
stris converted into a patch actiondictis treated as context forrender_block(...)HttpResponseis passed through after Hyper headers are ensured
HTML(...)
Arguments:
content: str | None = Nonetarget: str | None = Noneswap: str = "outer"transition: bool = Falsefocus: str | None = Noneswap_delay: int | None = Nonesettle_delay: int | None = Nonestrict_targets: bool | None = None
Argument details:
contentHTML string to patch into the pagetargetCSS selector the client runtime should patchswapDOM insertion mode. Supported values:inner,outer,before,after,prepend,append,delete,none.transitionWhether to request view-transition-aware patchingfocusFocus mode after patching. Common values are handled by the client runtime such as preserving focus or moving to the first invalid field.swap_delayDelay before the swap step startssettle_delayDelay before the settle step completesstrict_targetsWhether missing targets should fail loudly for this patch
Event emitted to the client runtime:
patch_html
Delete(target)
Arguments:
target: str
Behavior:
- translated into an HTML patch with
swap="delete"
Event emitted to the client runtime:
patch_html
Event(name, payload=None, target=None)
Arguments:
name: strpayload: dict[str, Any] | None = Nonetarget: str | None = None
Behavior:
- if
targetis provided, the event is dispatched on that element - otherwise the event is dispatched on
window
Event emitted to the client runtime:
dispatch_event
Toast(payload)
Arguments:
payload: Any
Behavior:
- emitted to the client as
hyper:toast - your frontend chooses how to display it
Event emitted to the client runtime:
toast
Redirect(url, replace=False)
Arguments:
url: strreplace: bool = False
Behavior:
- redirects the browser immediately
- if returned from a list or generator, treat it as the last item because later items are not delivered
Event emitted to the client runtime:
redirect
History(push_url=None, replace_url=None)
Arguments:
push_url: str | None = Nonereplace_url: str | None = None
Behavior:
push_urladds a history entryreplace_urlreplaces the current history entry- no full redirect occurs
Event emitted to the client runtime:
history
LoadJS(src)
Arguments:
src: str
Behavior:
- loads a module script dynamically after the action response reaches the client
Event emitted to the client runtime:
load_js
Signal(name, value)
Arguments:
name: strvalue: Any
Behavior:
countpatches the nearest Alpinex-data$countpatchesAlpine.store("hyper")
Event emitted to the client runtime:
patch_signals
Signals(values)
Arguments:
values: dict[str, Any]
Behavior:
- patches multiple Alpine values at once
Event emitted to the client runtime:
patch_signals