1

私は、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]}

テンプレート test.html:

{% load tegs_test %}
{% test_something %}

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

おわり メインをsetting.INSTALLED_APPSに登録します。test.htmlを開こうとするとエラーが発生します:

レンダリング中に RuntimeError をキャッチしました: Python オブジェクトの呼び出し中に最大再帰深度を超えました

この問題を解決するのを手伝ってください。ありがとう。

4

1 に答える 1

2

{% test_something %}template を呼び出し、test.html再び呼び出し{% test_something %}ます...

タグで別のテンプレートを指すか、代わりにフィルターを使用する必要があります。

于 2012-07-05T10:30:12.253 に答える