django发送错误报告显示{% elif tag%}行

mklgxw1f  于 2023-05-23  发布在  Go
关注(0)|答案(1)|浏览(117)
{% if category %}
    {% with posts=category.blogpost_set.all %}
        {% for post in posts %}
            {% include 'blog/compenent/_post.html' %}
        {% endfor %}
{% elif tag %}
    {% with posts=tag.blogpost_set.all %}
        {% for post in posts %}
            {% include 'blog/compenent/_post.html' %}
        {% endfor %}
    {% endwith %}
{% endif %}

message:emplateSyntaxError:第20行上的块标记无效:“elif”,应为“endwith”。您是否忘记注册或加载此标签?

aelbi1ox

aelbi1ox1#

您需要以先从{% with posts=… %}开始的方式结束,因此:

{% if category %}
    {% with posts=category.blogpost_set.all %}
        {% for post in posts %}
            {% include 'blog/compenent/_post.html' %}
        {% endfor %}
    {% endwith %}
{% elif tag %}
    {% with posts=tag.blogpost_set.all %}
        {% for post in posts %}
            {% include 'blog/compenent/_post.html' %}
        {% endfor %}
    {% endwith %}
{% endif %}

相关问题