我所拥有的(形象),所以我需要把这些卡片分成4-5张每行5张.我的解决方案很简单
<div class="card-deck">
{% for book in books %}
{% include 'books/book_element.html' %}
{% endfor %}
</div>我尝试了一段时间,并在做一些头脑风暴
{% for book in books %}
{% if forloop.counter|divisibleby:"5" or forloop.counter == 1 %}
<div class="card-deck">
</div>
{% endif %}
{% endfor %}如何将模板包含到div.Card牌中?
发布于 2018-03-17 07:06:45
您需要关闭前一行并在循环中打开一个新行。就像这样:
<div class="card-deck">
{% for book in books %}
{% include 'books/book_element.html' %}
{% if forloop.counter|divisibleby:"5" %}
{# Close the current deck and start a new one %}
</div><div class="card-deck">
{% endif %}
{% endfor %}
</div><!-- The final deck is closed here, outside the loop -->https://stackoverflow.com/questions/49331243
复制相似问题