django-components/sampleproject/components/recursive.py
Juro Oravec a49f5e51dd
feat: component URL (#1088)
* feat: allow to set defaults

* refactor: remove input validation and link to it

* feat: component URL

* refactor: fix linter errors

* refactor: fix linter errors + update examples to use Component.View..get

* docs: update comment

* refactor: revert change to hash_comp_cls

* docs: update comment
2025-04-07 10:44:41 +02:00

33 lines
888 B
Python

import time
from typing import Any, Dict
from django_components import Component, register, types
@register("recursive")
class Recursive(Component):
class View:
def get(self, request):
time_before = time.time()
output = Recursive.render_to_response(
request=request,
kwargs={
"depth": 0,
},
)
time_after = time.time()
print("TIME: ", time_after - time_before)
return output
def get_context_data(self, depth: int = 0) -> Dict[str, Any]:
return {"depth": depth + 1}
template: types.django_html = """
<div id="recursive">
depth: {{ depth }}
<hr/>
{% if depth <= 100 %}
{% component "recursive" depth=depth / %}
{% endif %}
</div>
"""