---
# GENERATED FILE — do not edit.
# Source: `manage.py docs_generate` (djust 1.2.0).
# Edit the generator in docs_app/generator.py instead.
title: "Lifecycle methods"
description: "Lifecycle methods on the LiveView base class, generated."
level: reference
order: 40
section: reference
generated: true
---
Lifecycle methods on `LiveView`, generated from the framework manifest.

**7 entries.**

## `connected`

```text
def connected(self):
```

**Phase:** `lifecycle`

Called when WebSocket connection is established after initial HTTP load.

## `disconnected`

```text
def disconnected(self):
```

**Phase:** `lifecycle`

Called when WebSocket connection is lost (before unmount).

## `get_context_data`

```text
self.get_context_data(**kwargs: Any) -> Dict[str, Any]
```

| Parameter | Default and behavior |
| --- | --- |
| `**kwargs` |  `Any`. |

**Phase:** `rendering`

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

## `handle_params`

```text
self.handle_params(params: Dict[str, Any], uri: str) -> None
```

| Parameter | Default and behavior |
| --- | --- |
| `params` | **Required.** `Dict[str, Any]`. The URL query parameters as a dict. |
| `uri` | **Required.** `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`

```text
self.handle_tick() -> None
```

**Phase:** `lifecycle`

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

## `mount`

```text
self.mount(request: 'HttpRequest', **kwargs: Any) -> None
```

| Parameter | Default and behavior |
| --- | --- |
| `request` | **Required.** `HttpRequest`. The Django request object **kwargs: URL parameters |
| `**kwargs` |  `Any`. |

**Phase:** `initialization`

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

## `unmount`

```text
def unmount(self):
```

**Phase:** `teardown`

Called when WebSocket disconnects. Clean up resources here.

## Initialize state and expose context

```python
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](/core-concepts/liveview/) for lifecycle behavior and
[Navigation](/guides/navigation/) for `handle_params()`.
