How To Use Django Cycle Tag

帅比萌擦擦* 提交于 2019-12-05 05:58:18

For the cycle tag, the two arguments will be added alternately to the template, for example, the code in your template {% for o in some_list %}<tr class="{% cycle 'row1' 'row2' %}"></tr>{% endfor %} would generate:

<tr class="row1">
    ...
</tr>
<tr class="row2">
    ...
</tr>
<tr class="row1">
    ...
</tr>
<tr class="row2">
    ...
</tr>
<!-- ... and so on while there are elements in some_list -->

And so on. Normally you would attach some css to this, for example:

<style>
   .row1 {
      background: #345678;
   }
   .row2 {
      background: #123456;
   }
</style>

This would give alternate rows different background colours, for example.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!