亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

為什么我的每個個人資料都返回自己的行而不是 3 行?

為什么我的每個個人資料都返回自己的行而不是 3 行?

江戶川亂折騰 2022-11-29 16:55:58
所以,我有一個循環遍歷我的用戶配置文件并隨機顯示其中的一些。我應該為每一行返回 3 個配置文件,但我讓每個配置文件都有自己的行。我在這里做錯了什么>{% for profile in random_profiles %}  <div class="row">    <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></div>{% endfor %}
查看完整描述

1 回答

?
慕沐林林

TA貢獻2016條經驗 獲得超9個贊

您正在為每個配置文件創建一行。標記在 for 循環內。我想要么你必須使用 2 個循環,一個用于配置文件,另一個用于每行中的配置文件數量,或者保持計數,如果計數達到 4,則創建額外的行,然后重置計數。實現第二種方法的方法之一可以是 -


{% 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 %}


查看完整回答
反對 回復 2022-11-29
  • 1 回答
  • 0 關注
  • 88 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號