第 7 行的块标记无效:"endif",预期为"空"或"endfor"。您是否忘记注册或加载此标签?



我是html模板和Django的初学者。

author_list.html

{% extends "base_generic.html" %}
{% block content %}
<h1>All authors</h1>
<ul>
{% for author in author_list %}
<li><a href="">{{ author.last_name }}:</a> {% for book in author.book_set.all %} {{ book.title }} {% if not
forloop.last %}, {% endif %}{% endfor %}</li>
{% endfor %}
</ul>
{% endblock %}

错误:第7行无效的块标记:'endif',预期为'empty'或'endfor'。您是否忘记注册或加载这个标签?

我有代码块。它在没有block if的情况下工作,但在条件句中不起作用。如何修复它。的帮助!粘贴" ">

你应该在多行上写模板标签。模板标记应该在同一行上开始(以{%)并结束(以%})。否则Django模板语言解析器会在此错误。因此,您应该将其重写为:

{% extends "base_generic.html" %}
{% block content %}
<h1>All authors</h1>
<ul>
{% for author in author_list %}
<!--                                                                                                 same line ↓ -->
<li><a href="">{{ author.last_name }}:</a> {% for book in author.book_set.all %} {{ book.title }} {% if not forloop.last %}, {% endif %}{% endfor %}</li>
{% endfor %}
</ul>
{% endblock %}

相关内容

最新更新