djust docs
Browse documentation
reference

Push-event methods

Push-event methods on the LiveView base class, generated.

Push-event methods on LiveView, generated from the framework manifest.

1 entries.

push_event

self.push_event(event: str, payload: Dict[str, Any] = None) -> None
ParameterDefault and behavior
eventRequired. str. Event name (e.g. "chart_update", "djust:scroll_to")
payloadDefault: None. Dict[str, Any]. Dict of data to send with the event

Push a custom event to the client. Client receives via dj-hook handleEvent() or window event listener.

Send an update to a browser hook

Call push_event() from your event handler. Events are queued and delivered after the handler response. The payload should contain JSON-serializable data.

from djust.decorators import event_handler

@event_handler()
def announce(self, **kwargs):
    self.push_event("status_changed", {"message": "Ready"})

Register a hook in your client script:

window.djust.hooks.StatusMessage = {
    mounted() {
        this.handleEvent("status_changed", (payload) => {
            this.el.textContent = payload.message;
        });
    }
};

Attach it to the element that displays the message:

<p dj-hook="StatusMessage" role="status"></p>

Use ordinary view state for template updates. Use a pushed event when a hook needs to control a browser API or a third-party widget. The hooks guide explains client-to-server events, hook lifecycle, and cleanup.