user1456308
user1456308

Reputation:

Django inclusion_tag issue

I try to create simplest include tag with inclusion_tag.

\main
    \templatetags
        \tegs_test.py
        \__init__.py

Python tegs_test.py:

from django import template

register = template.Library()

@register.inclusion_tag('test.html')
def test_something():
    return {'test_list':[1,2,3,4,5]}

Template test.html:

{% load tegs_test %}
{% test_something %}

{% for i in test_list %}
    {{ i }}
{% endfor %}

End I register main in setting.INSTALLED_APPS. when I try to open test.html getting error:

Caught RuntimeError while rendering: maximum recursion depth exceeded while calling a Python object

Please, help to solve this issue. Thanks.

Upvotes: 1

Views: 606

Answers (1)

JamesO
JamesO

Reputation: 25936

{% test_something %} calls the template test.html, which again calls {% test_something %} and so on...

You need to point to a different template withing your tag or use a filter instead.

Upvotes: 2

Related Questions