django靜態html中做動態變化

來源:互聯網
上載者:User

標籤:業務   動態   cat   商務邏輯   cti   class   繼承   color   equal   

在搭建網站中經常有篩選分類的需求

在django中為了簡便,我們經常將某些相同部分的內容取出來單獨存放形成一個base模板,其他的template繼承這個base就可以使用其中的內容

但是這些相同的部分如果有動態內容怎麼辦,例如篩選條件中的全部是選中的,但是其他條件未選擇,我們做好商務邏輯之後,返回的模板中應該是其他條件選中,全部未選中。如何?呢

可以使用ifequal來實現,

          <li>            <h2>機構類別</h2>            <div class="cont">              <a href="?city={{ city_id }}"><span class="{% ifequal category ‘‘ %}active2{% endifequal %}">全部</span></a>              <a href="?ct=pxjg&city={{ city_id }}"><span class="{% ifequal category ‘pxjg‘ %}active2{% endifequal %}">培訓機構</span></a>              <a href="?ct=gx&city={{ city_id }}"><span class="{% ifequal category ‘gx‘ %}active2{% endifequal %}">高校</span></a>              <a href="?ct=gr&city={{ city_id }}"><span class="{% ifequal category ‘gr‘ %}active2{% endifequal %}">個人</span></a>            </div>          </li>

我們只需要在模板中傳入響應的值即可。但個人覺得這個方法不是最好的方法。不過聊勝於無。

 

django靜態html中做動態變化

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.