1. 程式人生 > >django靜態html中做動態變化

django靜態html中做動態變化

部分 html中 應該 搭建 class emp amp 類別 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中做動態變化