mirror of
https://github.com/django-components/django-components.git
synced 2025-08-29 10:24:05 +00:00

* 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
33 lines
888 B
Python
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>
|
|
"""
|