【发布时间】:2020-04-14 20:20:25
【问题描述】:
我正在尝试使用引导卡。但我有问题。 当我添加新帖子以显示为卡片时,我显示超过 5 个,它们开始挤压。 每次显示超过 5 张卡片时,我都会尝试使用 forloop 计数器开始新行。 但我做错了什么。我读了所有的东西,到处都是一样的。但我肯定做错了。
<div class="card-deck">
{% for post in post_list %}
{% if forloop.counter0|divisibleby:3 %}
<div class="card border-primary mb-3" style="max-width: 20rem;">
<a href="{% url 'post_detail' post.slug %}">
<img style="height: 200px; width: 100%; display: block;" src="{{ post.thumb.url }}" alt="Card image"></a>
<div class="card-header">Header</div>
<div class="card-body">
<h4 class="card-title">{{ post.title }}</h4>
<p class="card-text">{{post.content|slice:":200" }}</p>
</div>
</div> {% endif %}
</div>
</div> {% endfor %}
【问题讨论】:
-
我猜你只呈现每三个帖子?
-
你将如何制作新行?
-
是的,我希望每 3-4 个帖子呈现一次。现在它只渲染了两个帖子。就是这样。
-
我想我没有正确理解你,对不起。我希望渲染所有帖子。分成几行。 3-4 个帖子(卡片)排成一行。然后是下面的帖子(卡片)。如果这对你有意义。
标签: django for-loop bootstrap-4 counter