django:第二个for循环不产生任何元素
我正在获取一个记录集,并执行一个 for 循环来显示数据,如下所示:
{% for category in categories %}
{"img":"{{ category.pr_image }}",
"url":"{{ category.pr_store_url }}",
"type":"ca",
"price":"{{ category.pr_price }}",
"store":"{{ category.pr_store }}",
"name":"{{ category.pr_name }}",
"lat":"{{ category.st_lat }}",
"long":"{{ category.st_long }}"},
{% endfor %}
效果很好。
然而,我有几行代码,但效果不太好:
{% for category in categories %}
<li class="msli">
<ul class="detali">
<li><a href="{{ category.pr_store_url }}" target="_blank">{{ category.pr_store }}</a></li>
<li>Category: {{ category.pr_cat_name }}</li>
</ul>
</li>
{% endfor %}
据我所知,它是相同的代码,只是格式不同。 如果代码 1 产生一个结果,则代码 2 确实产生一个输出,但不产生数据。 输出只有:
<li class="msli">
<ul class="detali">
<li><a target="_blank" href=""/></li>
<li>Category: </li>
</ul>
</li>
并且没有数据...... 我究竟做错了什么?
哦,两个 for 循环都包含在 if 情况中......
{% if products or stores or categories %}
I'm fetching a recordset, and doing a for loop to display the data like so:
{% for category in categories %}
{"img":"{{ category.pr_image }}",
"url":"{{ category.pr_store_url }}",
"type":"ca",
"price":"{{ category.pr_price }}",
"store":"{{ category.pr_store }}",
"name":"{{ category.pr_name }}",
"lat":"{{ category.st_lat }}",
"long":"{{ category.st_long }}"},
{% endfor %}
That works great.
However, a few lines of code down the line i have this, which does not work so great:
{% for category in categories %}
<li class="msli">
<ul class="detali">
<li><a href="{{ category.pr_store_url }}" target="_blank">{{ category.pr_store }}</a></li>
<li>Category: {{ category.pr_cat_name }}</li>
</ul>
</li>
{% endfor %}
As far as i can tell it's the same code, only different formating. If code 1 produces one result, Code 2 does produce one output, but no data. The output is only:
<li class="msli">
<ul class="detali">
<li><a target="_blank" href=""/></li>
<li>Category: </li>
</ul>
</li>
And no data...
What am i doing wrong?
Oh, and both for cycles are wrapped in a if case...
{% if products or stores or categories %}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我的错是,这是另一个类别触发了输出,上面的代码一切正常。
My bad, it was another category that was triggering the output, all is well with the code above.