【问题标题】:Django template: Invalid block tag: 'endif', expected 'empty' or 'endfor'Django模板:无效的块标签:'endif',预期的'empty'或'endfor'
【发布时间】:2015-07-08 04:51:53
【问题描述】:

我收到一条错误消息,提示我的模板不正确。

错误如下:无效的块标签:'endif',预期为'empty'或'endfor'

我的代码在这里,错误在最后一行。哪一部分不正确?

{% if entries %}
{% for entry in entries %}
<section class="no-padding" id="portfolio">
    <div class="container-fluid">
        (% if entry.scammer_name %}
        <div class="row no-gutter result-wrapper control-group">
            <div class="col-lg-3 result-label">
                <label class="control-group result-padding">
                    suspect's name:
                </label>
            </div>    
            <div class="col-lg-9 result">
                <label class="control-group result-padding light-font">
                    {{ entry.scammer_name }}
                </label>
            </div>    

        </div>
        {% endif %}
    </div>
</section>
{% endfor %}
{% endif %}

【问题讨论】:

  • 这是唯一的代码吗?
  • @Rohan 没有,我已经编辑过了……完整版如图

标签: html django django-templates


【解决方案1】:

在最后一行代码中添加{% endfor %}{% endif %}

【讨论】:

  • (% if entry.scammer_name %} 更改为{% if entry.scammer_name %}
【解决方案2】:

for循环需要endfor标签

{% if mike %}
  {% if jake %}
    {% for x in squid %}
      {{ x.do_stuff }}
    {% endfor %}
  {% endif %}{# closes jake tag #}
{% endif %}{# closes mike tag #}

【讨论】:

  • 其实有的,我没放这里。完整版如图,但还是有问题。
猜你喜欢
  • 1970-01-01
  • 2013-06-10
  • 2012-05-03
  • 2023-03-26
  • 2021-12-08
  • 2015-09-16
  • 1970-01-01
  • 2017-03-03
  • 2017-08-05
相关资源
最近更新 更多