{% extends "django_sample_components/pages/master_async.html" %} {% load sample_tags async_tags %} {% block title %}Toast{% endblock %} {% block content %} {# Toast container — Django messages fire automatically on load #} {% simple_toast %}
Self-contained toast notification component powered by Bootstrap.
The four Django messages queued by the view were displayed as toasts on page load.
Call window.showToast(message, type) from anywhere.
Submit the form below. The view sets
HX-Trigger: {"showToast": {"message": "...", "type": "success"}}
on a valid submission, which fires the toast automatically.
{% verbatim %}{% load sample_tags %}
{# 1. Include once — renders container + JS #}
{% simple_toast %}
{% simple_toast position="top-end" %}
{% simple_toast autohide=False delay=3000 %}
{# 2. Django messages fire automatically — no extra code needed #}
# views.py
messages.success(request, "Saved!")
{# 3. Plain JS #}{% endverbatim %}
window.showToast("Hello!", "success")
{% verbatim %}
{# 4. HTMX — from the view: #}{% endverbatim %}
response["HX-Trigger"] = json.dumps({"showToast": {"message": "Done!", "type": "success"}})