简体   繁体   English

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

[英]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.

相关问题 TemplateSyntaxError at /music/ 第 6 行的无效块标记:&#39;path&#39;,预期为 &#39;empty&#39; 或 &#39;endfor&#39;。 您是否忘记注册或加载此标签? - TemplateSyntaxError at /music/ Invalid block tag on line 6: 'path', expected 'empty' or 'endfor'. Did you forget to register or load this tag? Django - 无效的块标记..'else',预期为 'empty' 或 'endfor'。 您是否忘记注册或加载此标签? - Django - Invalid block tag..'else', expected 'empty' or 'endfor'. Did you forget to register or load this tag? Django:第 14 行的块标记无效:“endblock”,预期为“endfor”。 您是否忘记注册或加载此标签? - Django: Invalid block tag on line 14: 'endblock', expected 'endfor'. Did you forget to register or load this tag? 第 10 行的块标记无效:“endblock”,预期为“empty”或“endfor”。 您是否忘记注册或加载此标签? django(蟒蛇) - Invalid block tag on line 10: 'endblock', expected 'empty' or 'endfor'. Did you forget to register or load this tag? django (python) Django TemplateSyntaxError:“ endblock”,预期为“空”或“ endfor”。 您是否忘记注册或加载此标签? - Django TemplateSyntaxError: 'endblock', expected 'empty' or 'endfor'. Did you forget to register or load this tag? 第 8 行的块标记无效:“crsf_token”,应为“endblock”。 您是否忘记注册或加载此标签? - Invalid block tag on line 8: 'crsf_token', expected 'endblock'. Did you forget to register or load this tag? 第 24 行的块标记无效:“form.as_p”,应为“endblock”。 您是否忘记注册或加载此标签? - Invalid block tag on line 24: 'form.as_p', expected 'endblock'. Did you forget to register or load this tag? 无效的块标记。 您是否忘记注册或加载此标记? - Invalid block tag. Did you forget to register or load this tag? 无效的块标记:'endblock'。 您是否忘记注册或加载此标签? - Invalid block tag : 'endblock'. Did you forget to register or load this tag? 无效的块标记:&#39;endblock&#39;。 您是否忘记注册或加载此标签? - Invalid block tag: 'endblock'. Did you forget to register or load this tag?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM