diff --git a/htpy/__init__.py b/htpy/__init__.py index 6acc3e1..f9141ad 100644 --- a/htpy/__init__.py +++ b/htpy/__init__.py @@ -194,6 +194,12 @@ def __iter__(self) -> Iterator[str]: def __repr__(self) -> str: return f"<{self.__class__.__name__} '{self}'>" + # Avoid having Django "call" a htpy element that is injected into a + # template. Setting do_not_call_in_templates will prevent Django from doing + # an extra call: + # https://docs.djangoproject.com/en/5.0/ref/templates/api/#variables-and-lookups + do_not_call_in_templates = True + class Element(BaseElement): def __getitem__(self: ElementSelf, children: Node) -> ElementSelf: diff --git a/tests/test_django.py b/tests/test_django.py index 0cbae25..93a2202 100644 --- a/tests/test_django.py +++ b/tests/test_django.py @@ -11,9 +11,9 @@ def test_template_injection() -> None: t = Template("