Mixin reference
Every LiveView mixin: what it adds and its public methods, generated.
On this page
The mixins a LiveView is built from, generated from the framework's classes.
Add an opt-in mixin before LiveView in the class bases. The built-in ones
are already part of every LiveView: their methods are on self with no
import.
from djust import FormMixin, LiveView
class ContactView(FormMixin, LiveView):
form_class = ContactForm
Opt-in mixins (9)
ReactMixin
from djust import ReactMixin
Mixin for LiveView classes to add React component support.
get_react_components
self.get_react_components() -> djust.react.ReactComponentRegistry
Override to provide custom component registry.
render_react_component
self.render_react_component(name: str, props: Dict[str, Any], children: str = '') -> str
Render a React component within this view.
FormMixin
from djust import FormMixin
Mixin for LiveView classes to add Django Forms support with real-time validation.
mount
self.mount(request: Any, **kwargs: Any) -> None
Initialize form on view mount
form_instance
Property, settable. Access the form instance (re-creates if lost after serialization).
validate_field
self.validate_field(
field: str = '',
field_name: str = '',
value: Any = None,
**kwargs: Any,
) -> None
Validate a single field in real-time.
submit_form
self.submit_form(**kwargs: Any) -> None
Handle form submission.
reset_form
self.reset_form(**kwargs: Any) -> None
Reset the form to its initial state.
get_field_value
self.get_field_value(field_name: str, default: Any = '') -> Any
Get current value for a field
get_field_errors
self.get_field_errors(field_name: str) -> List[str]
Get errors for a specific field
has_field_errors
self.has_field_errors(field_name: str) -> bool
Check if a field has errors
as_live
self.as_live(**kwargs: Any) -> str
Render the entire form automatically using the configured CSS framework.
as_live_field
self.as_live_field(field_name: str, adapter: Any = None, **kwargs: Any) -> str
Render a single form field automatically using the configured CSS framework.
WizardMixin
from djust import WizardMixin
Multi-step form wizard mixin for djust LiveViews.
mount
self.mount(request: Any, **kwargs: Any) -> None
Initialise wizard state on first load.
as_live_field
self.as_live_field(
field_name: str,
event_name: str = 'validate_field',
**kwargs: Any,
) -> str
Render a form field as HTML with djust event bindings.
get_context_data
self.get_context_data(**kwargs: Any) -> Dict[str, Any]
Inject wizard state into the template context.
next_step
self.next_step(**kwargs: Any) -> None
Validate the current step and advance to the next one.
prev_step
self.prev_step(**kwargs: Any) -> None
Go back one step without validation.
go_to_step
self.go_to_step(step_index: int = 0, **kwargs: Any) -> None
Jump to a specific already-completed step for editing.
update_step_field
self.update_step_field(field: str = '', value: Any = '', **kwargs: Any) -> None
Store a single field value for the current step.
validate_field
self.validate_field(
field: str = '',
field_name: str = '',
value: Any = '',
**kwargs: Any,
) -> None
Store a field value triggered by as_live_field() dj-change events.
submit_wizard
self.submit_wizard(**kwargs: Any) -> None
Validate all steps and call on_wizard_complete() if everything passes.
on_wizard_complete
self.on_wizard_complete(step_data: dict[str, typing.Any]) -> None
Called when the wizard is fully completed and all steps are valid.
DraftModeMixin
from djust import DraftModeMixin
Mixin for LiveView classes to enable automatic draft saving to localStorage.
get_draft_key
self.get_draft_key() -> str
Get the draft key for localStorage.
clear_draft
self.clear_draft() -> None
Clear the draft from localStorage.
get_context_data
self.get_context_data(**kwargs: Any) -> dict[str, typing.Any]
Add draft configuration to template context.
PresenceMixin
from djust import PresenceMixin
Mixin that provides presence tracking capabilities to LiveView.
get_presence_key
self.get_presence_key() -> str
Get the presence key for this view instance.
get_presence_user_id
self.get_presence_user_id() -> str
Get the unique user identifier for presence tracking.
track_presence
self.track_presence(meta: Optional[Dict[str, Any]] = None) -> None
Start tracking this user's presence.
untrack_presence
self.untrack_presence() -> None
Stop tracking this user's presence.
list_presences
self.list_presences() -> List[Dict[str, Any]]
Get all active presences for this view's presence group.
presence_count
self.presence_count() -> int
Get the count of active users in this view's presence group.
update_presence_heartbeat
self.update_presence_heartbeat() -> None
Update the heartbeat for this user's presence.
handle_presence_join
self.handle_presence_join(presence: Dict[str, Any]) -> None
Called when a user joins the presence group.
handle_presence_leave
self.handle_presence_leave(presence: Dict[str, Any]) -> None
Called when a user leaves the presence group.
broadcast_to_presence
self.broadcast_to_presence(event: str, payload: Optional[Dict[str, Any]] = None) -> None
Broadcast an event to all users in the presence group.
LiveCursorMixin
from djust import LiveCursorMixin
Extends PresenceMixin with live cursor tracking capabilities.
update_cursor_position
self.update_cursor_position(x: int, y: int) -> None
Update cursor position for this user.
get_cursors
self.get_cursors() -> Dict[str, Dict[str, Any]]
Get all active cursor positions for this presence group.
handle_cursor_move
self.handle_cursor_move(x: int, y: int) -> None
Handler called when cursor position is received from client.
untrack_presence
self.untrack_presence() -> None
Override to also remove cursor when leaving presence.
UploadMixin
from djust import UploadMixin
Mixin that adds file upload support to a LiveView.
allow_upload
self.allow_upload(
name: str,
accept: str = '',
max_entries: int = 1,
max_file_size: int = 10000000,
chunk_size: int = 65536,
auto_upload: bool = True,
writer: Optional[Type[djust.uploads.UploadWriter]] = None,
resumable: bool = False,
allow_active_content: bool = False,
) -> djust.uploads.UploadConfig
Configure a named upload slot.
consume_uploaded_entries
self.consume_uploaded_entries(
name: str,
) -> Generator[djust.uploads.UploadEntry, NoneType, NoneType]
Consume completed upload entries for the named slot.
cancel_upload
self.cancel_upload(name: str, ref: str) -> None
Cancel a specific upload by ref.
get_uploads
self.get_uploads(name: str) -> List[djust.uploads.UploadEntry]
Get all entries (including in-progress) for an upload slot.
LoginRequiredMixin
from djust import LoginRequiredMixin
Mixin that sets login_required = True. Django-familiar convenience.
PermissionRequiredMixin
from djust import PermissionRequiredMixin
Mixin that enforces permission_required. Set the attribute on your view.
Built into LiveView (22)
ContextProviderMixin
Included in LiveView.
Component/view context sharing — React Context API equivalent (v0.5.1).
provide_context
self.provide_context(key: str, value: Any) -> None
Expose a value to descendant components under key.
consume_context
self.consume_context(key: str, default: Any = None) -> Any
Return the value provided under key by this node or any ancestor.
clear_context_providers
self.clear_context_providers() -> None
Reset all context providers — called at the start of each render.
StreamsMixin
Included in LiveView. To name it, from djust.mixins import StreamsMixin.
Methods for managing streams: stream, stream_insert, stream_delete, stream_reset.
stream
self.stream(
name: str,
items: Any,
dom_id: Optional[Callable[[Any], str]] = None,
at: int = -1,
reset: bool = False,
limit: Optional[int] = None,
) -> djust.session_utils.Stream
Initialize or update a stream with items.
stream_prune
self.stream_prune(name: str, limit: int, edge: str = 'top') -> None
Cap a stream at limit items, removing the surplus rows from the page on the next render.
stream_insert
self.stream_insert(name: str, item: Any, at: int = -1) -> None
Insert an item into a stream (-1 = append, 0 = prepend).
stream_delete
self.stream_delete(name: str, item_or_id: Any) -> None
Delete an item from a stream by item or id.
stream_reset
self.stream_reset(name: str, items: Any = None) -> None
Reset a stream, clearing all items and optionally adding new ones.
StreamingMixin
Included in LiveView. To name it, from djust import StreamingMixin.
Mixin that provides streaming capabilities for LiveView.
stream_to
self.stream_to(
stream_name: str,
target: Optional[str] = None,
html: Optional[str] = None,
) -> None
Send a streaming partial update to the client.
stream_text
self.stream_text(
stream_name: str,
text: str,
mode: str = 'append',
target: Optional[str] = None,
) -> None
Stream text content to a target element.
stream_error
self.stream_error(stream_name: str, error: str, target: Optional[str] = None) -> None
Send an error state to a stream target, preserving partial content.
stream_start
self.stream_start(stream_name: str, target: Optional[str] = None) -> None
Signal the start of a stream to the client.
stream_done
self.stream_done(stream_name: str, target: Optional[str] = None) -> None
Signal the end of a stream to the client.
push_state
self.push_state() -> None
Send current state to the client immediately (full re-render).
TemplateMixin
Included in LiveView. To name it, from djust.mixins import TemplateMixin.
Template-related methods: get_template, render, render_full_template, render_with_diff, and various HTML extraction/stripping helpers.
get_template
self.get_template() -> str
Get the Rust template source for this view.
render
self.render(request: Optional[ForwardRef('HttpRequest')] = None) -> str
Render the view to HTML.
arender_chunks
self.arender_chunks(full_html: str, emitter: 'ChunkEmitter') -> None
Async-generator producer that pushes shell-then-body chunks.
render_full_template
self.render_full_template(
request: Optional[ForwardRef('HttpRequest')] = None,
serialized_context: Optional[Dict[str, Any]] = None,
) -> str
Render the full template including base template inheritance. Used for initial GET requests when using template inheritance.
render_with_diff
self.render_with_diff(
request: Optional[ForwardRef('HttpRequest')] = None,
extract_liveview_root: bool = False,
preloaded_context: Optional[Dict[str, Any]] = None,
) -> Tuple[str, Optional[str], int]
Render the view and compute diff from last render.
ComponentMixin
Included in LiveView. To name it, from djust.mixins import ComponentMixin.
Component methods: mount, handle_component_event, update_component, etc.
mount
self.mount(request: 'HttpRequest', **kwargs: Any) -> None
Called when the view is mounted. Override to set initial state.
handle_component_event
self.handle_component_event(component_id: str, event: str, data: Dict[str, Any]) -> None
Handle events sent from child components.
update_component
self.update_component(component_id: str, **props: Any) -> None
Update a child component's props.
ContextMixin
Included in LiveView. To name it, from djust.mixins import ContextMixin.
Context methods: get_context_data, _get_context_processors, _apply_context_processors.
get_context_data
self.get_context_data(**kwargs: Any) -> Dict[str, Any]
Get the context data for rendering. Override to customize context.
RustBridgeMixin
Included in LiveView. To name it, from djust.mixins import RustBridgeMixin.
Rust integration: _initialize_rust_view, _sync_state_to_rust.
set_changed_keys
self.set_changed_keys(keys: Union[str, Iterable[str], NoneType] = None) -> None
Mark one or more public attrs as changed, forcing a re-render.
RequestMixin
Included in LiveView. To name it, from djust.mixins import RequestMixin.
HTTP handling: get, post.
get
self.get(
request: 'HttpRequest',
*args: Any,
**kwargs: Any,
) -> django.http.response.HttpResponse
Handle GET requests - initial page load.
aget
self.aget(
request: 'HttpRequest',
*args: Any,
**kwargs: Any,
) -> django.http.response.HttpResponse
Async-streaming GET path. PR-A foundation (ADR-015).
post
self.post(
request: 'HttpRequest',
*args: Any,
**kwargs: Any,
) -> django.http.response.HttpResponse
Handle POST requests - event handling
PostProcessingMixin
Included in LiveView. To name it, from djust.mixins import PostProcessingMixin.
Post-processing: get_debug_info, _hydrate_react_components, _inject_client_script.
get_debug_info
self.get_debug_info() -> Dict[str, Any]
Get debug information about this LiveView instance.
get_debug_update
self.get_debug_update() -> Dict[str, Any]
Get a slim debug payload for event responses (skip static handler metadata).
ModelBindingMixin
Included in LiveView. To name it, from djust.mixins import ModelBindingMixin.
Provides automatic update_model handler for dj-model bindings.
update_model
self.update_model(field: str = '', value: Any = None, **kwargs: Any) -> None
Default handler for dj-model changes from the client.
PushEventMixin
Included in LiveView. To name it, from djust.mixins import PushEventMixin.
Mixin that provides push_event() for sending events to client JS.
push_event
self.push_event(event: str, payload: Dict[str, Any] = None) -> None
Push an event to the connected client(s).
trigger_submit
self.trigger_submit(selector: str) -> None
Trigger a native HTML form POST on the client after this handler.
push_commands
self.push_commands(chain: 'JSChain') -> None
Push a JS Command chain to the current session for immediate execution.
flush_push_events
self.flush_push_events() -> None
Flush pending push events immediately via the consumer callback.
NavigationMixin
Included in LiveView. To name it, from djust.mixins import NavigationMixin.
Adds URL navigation capabilities to a LiveView.
live_patch
self.live_patch(
params: Optional[Dict[str, Any]] = None,
path: Optional[str] = None,
replace: bool = False,
) -> None
Update the browser URL without remounting the view.
live_redirect
self.live_redirect(
path: str,
params: Optional[Dict[str, Any]] = None,
replace: bool = False,
) -> None
Navigate to a different LiveView over the existing WebSocket.
handle_params
self.handle_params(params: Dict[str, Any], uri: str) -> None
Called after mount() on initial render AND on every subsequent URL change.
FlashMixin
Included in LiveView. To name it, from djust import FlashMixin.
Mixin that provides put_flash() and clear_flash() for LiveView.
put_flash
self.put_flash(level: str, message: str) -> None
Queue a flash message to be sent to the connected client.
clear_flash
self.clear_flash(level: Optional[str] = None) -> None
Queue a command to clear flash messages on the client.
PageMetadataMixin
Included in LiveView. To name it, from djust import PageMetadataMixin.
Mixin that provides page_title and page_meta property setters for LiveView.
page_title
Property, settable. Get the current page title.
page_meta
Property, settable. Get the current page meta tags.
LayoutMixin
Included in LiveView. To name it, from djust.mixins import LayoutMixin.
Mixin exposing :meth:set_layout for runtime layout switching.
set_layout
self.set_layout(template_path: str) -> None
Queue a layout swap to be applied after the current handler returns.
WaiterMixin
Included in LiveView. To name it, from djust.mixins import WaiterMixin.
Adds wait_for_event to a LiveView.
wait_for_event
self.wait_for_event(
name: 'str',
*,
timeout: 'Optional[float]' = None,
predicate: 'Optional[Callable[[Dict[str, Any]], bool]]' = None,
) -> 'Dict[str, Any]'
Suspend until an @event_handler named name is called.
AsyncWorkMixin
Included in LiveView. To name it, from djust.mixins import AsyncWorkMixin.
Mixin that provides start_async() for running slow work after flushing current state to the client.
start_async
self.start_async(
callback: Callable[..., Any],
*args: Any,
name: Optional[str] = None,
**kwargs: Any,
) -> None
Schedule a callback to run in a background thread after the current handler's state is flushed to the client.
cancel_async
self.cancel_async(name: str) -> None
Cancel a scheduled or running async task.
cancel_async_all
self.cancel_async_all() -> None
Cancel every scheduled and running start_async task on this view.
defer
self.defer(callback: Callable[..., Any], *args: Any, **kwargs: Any) -> None
Schedule a callback to run once, after the current render+patch cycle completes. Phoenix-style send(self(), :foo) semantics — useful for telemetry, post-render cleanup, or follow-up side effects that should fire after the user sees the change.
assign_async
self.assign_async(
name: str,
loader: Callable[..., Any],
*args: Any,
**kwargs: Any,
) -> None
High-level async data loading with built-in loading / ok / failed state.
NotificationMixin
Included in LiveView. To name it, from djust import NotificationMixin.
Subscribe a LiveView to PostgreSQL pg_notify channels.
listen
self.listen(channel: str) -> None
Subscribe this view to pg_notify on channel.
handle_info
self.handle_info(message: Dict[str, Any]) -> None
Receive out-of-band messages (e.g. pg_notify events).
ActivityMixin
Included in LiveView. To name it, from djust.mixins import ActivityMixin.
Per-LiveView registry of {% dj_activity %} regions.
set_activity_visible
self.set_activity_visible(name: 'str', visible: 'bool') -> 'None'
Flip the server-side visibility state of an activity.
is_activity_visible
self.is_activity_visible(name: 'str') -> 'bool'
Return the DECLARED visibility of an activity.
Internal
Also bases of LiveView, contributing no public methods to it: JITMixin, HandlerMixin, StickyChildRegistry.