首页 > 解决方案 > 无法向我的模板添加不同的块标签

问题描述

我正在尝试在 for 循环中添加不同的块标签,但它会引发错误

您是否忘记注册或加载此标签?

但是我注册了

{% for todo in todo_list %}
{% if todo.complete %}{% else %}

        {{todo.text|capfirst|truncatechars:150}} </a> <br>
        <small class="text-muted">{{todo.content|capfirst}}{% empty %} {% endif %} </small> <hr>

{% endif %}   {% endfor %}

谢谢

标签: djangopython-3.xdjango-templates

解决方案


调查你的问题,我认为你需要试试这个:

{% for todo in todo_list %}
    {% if todo.complete %}
    {% else %}
        {{todo.text|capfirst|truncatechars:150}} </a> <br>
        {% if todo.content %}
            <small class="text-muted">{{todo.content|capfirst}} </small> <hr>
        {% else %}
            //do something 
        {% endif %}  
    {% endif %} 
{% endfor %}

推荐阅读