django-components/docs/examples/recursion/README.md
Juro Oravec 49afdb49d6
Some checks are pending
Docs - build & deploy / docs (push) Waiting to run
Run tests / build (ubuntu-latest, 3.10) (push) Waiting to run
Run tests / build (ubuntu-latest, 3.11) (push) Waiting to run
Run tests / build (ubuntu-latest, 3.12) (push) Waiting to run
Run tests / build (ubuntu-latest, 3.13) (push) Waiting to run
Run tests / build (ubuntu-latest, 3.8) (push) Waiting to run
Run tests / build (ubuntu-latest, 3.9) (push) Waiting to run
Run tests / build (windows-latest, 3.10) (push) Waiting to run
Run tests / build (windows-latest, 3.11) (push) Waiting to run
Run tests / build (windows-latest, 3.12) (push) Waiting to run
Run tests / build (windows-latest, 3.13) (push) Waiting to run
Run tests / build (windows-latest, 3.8) (push) Waiting to run
Run tests / build (windows-latest, 3.9) (push) Waiting to run
Run tests / test_docs (3.13) (push) Waiting to run
Run tests / test_sampleproject (3.13) (push) Waiting to run
docs: Add "scenarios" code examples (#1445)
2025-10-08 00:17:31 +02:00

850 B

Recursion

Unlike other frameworks, django-components handles templates of any depth. 100 nested components? Not a problem!

In this example, the Recursion will recursively render itself 100 times.

{% component "recursion" / %}

This will produce a deeply nested structure of divs, with each level indicating its depth in the recursion.

Recursion

Definition

--8<-- "docs/examples/recursion/component.py"

Example

To see the component in action, you can set up a view and a URL pattern as shown below.

views.py

--8<-- "docs/examples/recursion/page.py"

urls.py

from django.urls import path

from examples.pages.recursion import RecursionPage

urlpatterns = [
    path("examples/recursion", RecursionPage.as_view(), name="recursion"),
]