from django.http import HttpRequest, HttpResponse from django.utils.safestring import mark_safe from django_components import Component, types class ErrorFallbackPage(Component): class Media: js = ( mark_safe( '' ), ) template: types.django_html = """ {% load component_tags %} ErrorFallback Example

Weather API Widget Example

This example demonstrates using ErrorFallback to handle potential API failures gracefully.

Case 1: API call is successful

{% component "error_fallback" %} {% fill "content" %} {% component "weather_widget" location="New York" / %} {% endfill %} {% fill "fallback" %} {% endfill %} {% endcomponent %}

Case 2: API call fails

{% component "error_fallback" %} {% fill "content" %} {% component "weather_widget" location="Atlantis" simulate_error=True / %} {% endfill %} {% fill "fallback" %} {% endfill %} {% endcomponent %}
""" # noqa: E501 class View: def get(self, request: HttpRequest) -> HttpResponse: return ErrorFallbackPage.render_to_response(request=request)