[英]Invalid block tag on line 7: 'endif', expected 'empty' or 'endfor'. Did you forget to register or load this tag?
I am beginner in html-templates and Django.我是 html 模板和 Django 的初学者。
author_list.html
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 %}
Error: Invalid block tag on line 7: 'endif', expected 'empty' or 'endfor'.错误:第 7 行的块标记无效:“endif”,预期为“empty”或“endfor”。 Did you forget to register or load this tag?
您是否忘记注册或加载此标签?
I have the block of code.我有代码块。 It works without block if, but doesn't work with the conditional.
它在没有阻塞 if 的情况下工作,但不适用于条件。 How to fix it.
如何修复它。 Help!
帮助! I should paste "," after each name of book.
我应该在每个书名之后粘贴“,”。
You should not write template tags on multiple lines.您不应该在多行上编写模板标签。 A template tag should start (with
{%
) and end (with %}
) on the same line.模板标签应该在同一行开始(以
{%
)和结束(以%}
)。 Otherwise the Django template language parser will error on this.否则 Django 模板语言解析器会出错。 You thus should rewrite this to:
因此,您应该将其重写为:
{% 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 %}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.