Home Features Docs Blog Philosophy Examples FAQ Live Demo Hosting
Documentation

Learn djust Inside & Out.

Everything you need to build reactive, real-time Django applications with djust.

Full documentation is on docs.djust.org

This page is a lightweight reference. The complete guide — with tutorials, theming, code examples, and more — lives on our dedicated docs site.

View on docs.djust.org

Core Concepts

Understanding the fundamental concepts behind djust's reactive server-side rendering.

Architecture

djust connects browser interactions to server-side state through WebSocket or HTTP. The client (Browser (Client)) contains DOM (HTML) and djust.js (~29KB gz), communicating via WebSocket/HTTP with the server (Server (Django)).

LiveView

A LiveView is a Django view that maintains state between requests and updates the UI reactively. Unlike traditional request-response views, LiveViews stay connected and can push updates to the client in real-time.

Lifecycle Methods

MethodWhen CalledPurpose
mount(request, **kwargs)Initial page loadInitialize state
render()After any state changeReturn HTML (auto-called)
handle_params(params)URL params changeReact to URL changes
terminate()Session endsCleanup resources

Example LiveView

views.py
 1from djust import LiveView, event_handler
 2
 3class CounterView(LiveView):
 4    template_name = 'counter.html'
 5
 6    def mount(self, request, **kwargs):
 7        """Called when the view first loads."""
 8        self.count = 0
 9
10    @event_handler
11    def increment(self):
12        """Event handler for increment button."""
13        self.count += 1
14
15    @event_handler
16    def decrement(self):
17        """Event handler for decrement button."""
18        self.count -= 1

Example Template

templates/counter.html
1<div dj-liveview>
2    <h1>Count: {{ count }}</h1>
3
4    <button dj-click="decrement">-</button>
5    <button dj-click="increment">+</button>
6</div>

Events

Events connect user interactions to server-side handlers. Use dj-* attributes in your templates to bind events.

Event Bindings

AttributeDescriptionExample
dj-clickHandle click events<button dj-click="increment">+1</button>
dj-inputHandle input on every keystroke<input dj-input="search" value="{{ search }}">
dj-changeHandle input on blur (leaving field)<input dj-change="update_email" value="{{ email }}">
dj-submitHandle form submission<form dj-submit="create_user">...</form>
dj-keydownHandle keyboard events<input dj-keydown="handle_key" dj-key="Enter">

Key Concepts

  • Server-Side State - All state lives on the server. No client-side state management needed.
  • Reactive Updates - When state changes, only the changed parts of the DOM are updated.
  • VDOM Diffing - Rust-powered virtual DOM calculates minimal patches for efficient updates.
  • Event Handlers - Any method can handle events. Use @event_handler decorator for explicit marking.

VDOM Architecture

djust uses a Rust-powered Virtual DOM for efficient updates. Instead of re-sending the entire page, only the differences (patches) are sent.

1. Server renders HTML template
2. Rust parses HTML into VDOM tree
3. Client receives initial HTML
4. On state change:
   a. Server re-renders template
   b. Rust diffs old vs new VDOM
   c. Only differences sent to client
   d. Client patches DOM surgically

Performance Benefit

ApproachUpdate 1 item in 1000-item list
Full re-renderSend ~50KB, replace entire DOM
djust VDOMSend ~100 bytes, patch 1 element

Next Steps