djust docs
Browse documentation
reference

Lifecycle methods

Lifecycle methods on the LiveView base class, generated.

On this page

Lifecycle methods on LiveView, generated from the framework manifest.

7 entries.

connected

def connected(self):

Phase: lifecycle

Called when WebSocket connection is established after initial HTTP load.

disconnected

def disconnected(self):

Phase: lifecycle

Called when WebSocket connection is lost (before unmount).

get_context_data

self.get_context_data(**kwargs: Any) -> Dict[str, Any]
ParameterDefault and behavior
**kwargsAny.

Phase: rendering

Return dict of template context variables. By default, all public (non-underscore) attributes are included automatically.

handle_params

self.handle_params(params: Dict[str, Any], uri: str) -> None
ParameterDefault and behavior
paramsRequired. Dict[str, Any]. The URL query parameters as a dict.
uriRequired. str. The full URI string (path + query string).

Phase: navigation

Called when URL params change (via live_patch or browser back/forward). Override to update state from URL.

handle_tick

self.handle_tick() -> None

Phase: lifecycle

Called periodically when tick_interval is set (in ms). Use for polling or periodic updates.

mount

self.mount(request: 'HttpRequest', **kwargs: Any) -> None
ParameterDefault and behavior
requestRequired. HttpRequest. The Django request object **kwargs: URL parameters
**kwargsAny.

Phase: initialization

Called once when the view is first loaded (HTTP GET) and when WebSocket connects. Initialize state here.

unmount

def unmount(self):

Phase: teardown

Called when WebSocket disconnects. Clean up resources here.

Initialize state and expose context

from djust import LiveView

class CounterView(LiveView):
    template_name = "myapp/counter.html"

    def mount(self, request, **kwargs):
        self.count = 0

    def get_context_data(self, **kwargs):
        context = super().get_context_data(**kwargs)
        context["doubled"] = self.count * 2
        return context

mount() runs during HTTP rendering and again for the WebSocket view; keep initialization safe to repeat. Use unmount() for resource cleanup. See LiveView concepts for lifecycle behavior and Navigation for handle_params().