【问题标题】:TemplateSyntaxError at endfor in jinja django codingjinja django编码中endfor的TemplateSyntaxError
【发布时间】:2020-10-15 18:43:11
【问题描述】:

jinja2 无法识别 {% endfor %} 并遇到此错误:

TemplateSyntaxError at endfor in jinja django coding

下面是sn-p的代码:

{% for dest in dests % }
               
  <!-- Destination -->
  <div class="destination item">
    <div class="destination_image">
      <img src="{{im}}/{{dest.img}}" alt="">
      <div class="spec_offer text-center"><a href="#">Special Offer</a></div>
    </div>
    <div class="destination_content">
      <div class="destination_title"><a href="{% static 'destinations.html' %}">{{dest.name}}</a></div>
      <div class="destination_subtitle"><p>{{dest.desc}}</p></div>
      <div class="destination_price">From ${{dest.price}}</div>
    </div>
  </div>

{% endfor %}

这里dest是一个显示内容的列表。

【问题讨论】:

  • 请告诉我们错误。 中的 {{im}} 是什么?
  • {% for dest in dests %you_have_space_here}

标签: python html django jinja2


【解决方案1】:

无法识别 forloop,因为您的 jinja 格式错误。百分比的开头和结尾不能有空格。更改为 this{% for dest in dests %}

当您为数据库获取图像时,最后需要 .url。所以你的代码应该看起来像&lt;img src="{{dest.img.url}}" alt=""&gt;

【讨论】:

    猜你喜欢
    • 2017-01-30
    • 1970-01-01
    • 2011-11-16
    • 2021-02-26
    • 2012-05-26
    • 2014-01-17
    • 2020-06-16
    • 2020-02-04
    • 1970-01-01
    相关资源
    最近更新 更多