【问题标题】:Django inclusion_tag issueDjango 包含标签问题
【发布时间】:2012-07-05 16:17:23
【问题描述】:

我尝试使用包含标签创建最简单的包含标签。

\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中注册main。 当我尝试打开 test.html 时出现错误:

渲染时捕获 RuntimeError:调用 Python 对象时超出最大递归深度

请帮忙解决这个问题。谢谢。

【问题讨论】:

  • test_someting 调用 test.html 模板,该模板再次调用 test_something 等等......您需要指向不同的模板,否则您会混淆标签/过滤器。
  • @JamesO 您应该将其添加为答案。

标签: python django


【解决方案1】:

{% test_something %} 调用模板test.html,它再次调用{% test_something %} 等等......

您需要使用标签指向不同的模板或使用过滤器。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-08-20
    • 2017-04-06
    • 1970-01-01
    • 2012-12-22
    • 2014-07-29
    • 1970-01-01
    • 1970-01-01
    • 2020-09-19
    相关资源
    最近更新 更多