{% 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 %}

Toast

Self-contained toast notification component powered by Bootstrap.


Django Messages (automatic)

The four Django messages queued by the view were displayed as toasts on page load.


Manual — via JavaScript

Call window.showToast(message, type) from anywhere.


HTMX — triggered by server response

Submit the form below. The view sets HX-Trigger: {"showToast": {"message": "...", "type": "success"}} on a valid submission, which fires the toast automatically.

{% async_sum_form %}

Usage
{% 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"}})
{% endblock %}