简体   繁体   English

Django TemplateSyntaxError:“ endblock”,预期为“空”或“ endfor”。 您是否忘记注册或加载此标签?

[英]Django TemplateSyntaxError: 'endblock', expected 'empty' or 'endfor'. Did you forget to register or load this tag?

I'm unsure where my syntax error is, if you can please spot it that would be great. 我不确定我的语法错误在哪里,如果可以的话,发现它会很棒。

{% extends 'budget/base.html' %}
{% block content %}
            <ul class="z-depth-1">

            {% for transaction in transaction_list %}
            <li>
                <div class="card-panel z-depth-0 transaction">
                    <div class="row">

                        <div class="col l5">
                            <span class="title"> {{ transaction.title }}</span>
                        </div>

                        <div class="col l5">
                            <span class="title">{{ transaction.amount }}</span>
                        </div>

                        <div class="col l1">
                            <span class="title bold">{{ transaction.category.name }}</span>
                        </div>

                        <a href="">
                            <i class="material-icons right"></i>
                        </a>
                    </div>
                </div>
            </li>
            {% endfor $}


        </ul>
    </section>
</div>
{% endblock content %}

And 'budget/base.html' looks like this: “ budget / base.html”看起来像这样:

{% load static %}
<link rel="stylesheet" href="{% static 'css/styles.css' %}">

<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
      content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>BudgetProject</title>

<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/css/materialize.min.css">
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">

</head>
<body>
    {% block content %}
    {% endblock %}
<script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/js/materialize.min.js"></script>
</body>
</html>

I tried looking at similar problems and I'm fairly certain the syntax for the for loop is correct. 我试着研究类似的问题,并且相当确定for循环的语法正确。 My code was working until I added the {% for x in y %} {% endfor %} 我的代码一直有效,直到我添加了{%for x in y%} {%endfor%}

you did a small mistake, please remove the $ sign from the {% endfor $} and add % instead. 您犯了一个小错误,请从{%endfor $}中删除$符号,然后添加%。 and in last line of your code replace {% endblock content %} with {% endblock %} so your code will look like as below: 然后在代码的最后一行中,将{%endblock content%}替换为{%endblock%},这样您的代码将如下所示:

    {% extends 'budget/base.html' %}
{% block content %}
            <ul class="z-depth-1">

            {% for transaction in transaction_list %}
            <li>
                <div class="card-panel z-depth-0 transaction">
                    <div class="row">

                        <div class="col l5">
                            <span class="title"> {{ transaction.title }}</span>
                        </div>

                        <div class="col l5">
                            <span class="title">{{ transaction.amount }}</span>
                        </div>

                        <div class="col l1">
                            <span class="title bold">{{ transaction.category.name }}</span>
                        </div>

                        <a href="">
                            <i class="material-icons right"></i>
                        </a>
                    </div>
                </div>
            </li>
            {% endfor %}


        </ul>
    </section>
</div>
{% endblock %}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 第 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:第 14 行的块标记无效:“endblock”,预期为“endfor”。 您是否忘记注册或加载此标签? - Django: Invalid block tag on line 14: 'endblock', expected 'endfor'. Did you forget to register or load this tag? 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? 第 7 行的块标记无效:&#39;endif&#39;,预期为 &#39;empty&#39; 或 &#39;endfor&#39;。 您是否忘记注册或加载此标签? - Invalid block tag on line 7: 'endif', expected 'empty' or 'endfor'. Did you forget to register or load this tag? Django 1.10 TemplateSyntaxError。 您是否忘记注册或加载此标签? - Django 1.10 TemplateSyntaxError. 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? 第 8 行的块标记无效:“crsf_token”,应为“endblock”。 您是否忘记注册或加载此标签? - Invalid block tag on line 8: 'crsf_token', expected 'endblock'. Did you forget to register or load this tag? 在模板'endblock'中。 您是否忘记注册或加载此标签? - In template 'endblock'. Did you forget to register or load this tag?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM