1 回答

TA貢獻(xiàn)2016條經(jīng)驗(yàn) 獲得超9個(gè)贊
您正在為每個(gè)配置文件創(chuàng)建一行。標(biāo)記在 for 循環(huán)內(nèi)。我想要么你必須使用 2 個(gè)循環(huán),一個(gè)用于配置文件,另一個(gè)用于每行中的配置文件數(shù)量,或者保持計(jì)數(shù),如果計(jì)數(shù)達(dá)到 4,則創(chuàng)建額外的行,然后重置計(jì)數(shù)。實(shí)現(xiàn)第二種方法的方法之一可以是 -
{% for profile in random_profiles %}
{% if forloop.first or forloop.counter0 % 4 == 0 %}
<div class="row">
{% endif %}
<div class="col-md-4">
<div class="card mb-4 shadow-sm">
<img src="{{ profile.photo.url }}" width="100%" height="225" xmlns="http://www.w3.org/2000/svg" preserveAspectRatio="xMidYMid slice" focusable="false" rect width="100%" height="100%" fill="#55595c"/><text x="50%" y="50%" fill="#eceeef" dy=".3em">Thumbnail</text></svg>
<div class="card-body">
<p class="card-text">This is a wider card with supporting text below as a natural lead-in to additional content. This content is a little bit longer.</p>
<div class="d-flex justify-content-between align-items-center">
<div class="btn-group">
<button type="button" class="btn btn-sm btn-outline-secondary">View</button>
<button type="button" class="btn btn-sm btn-outline-secondary">Edit</button>
</div>
<small class="text-muted">9 mins</small>
</div>
</div>
</div>
</div>
</div>
{% if forloop.first or forloop.counter0 % 4 == 0 %}
</div>
{% endif %}
{% endfor %}
添加回答
舉報(bào)