Since there is no modulus (%) in django templates So how to apply
cycle at this
{% for story in data %}
{{forloop.counter}}
when forloop.counter%4==1 then this should be executed
<div class="thumb">
<a href="#"><img src="{{ STATIC_URL }}images/thumb.jpg" width="185" height="185" /></a>
</div>
<div class="thumbFooter">
<span class="view">
<a href="#" class="viewIcon">{{ story.views }}</a>
</span>
<span class="like">
<a href="#" class="likeIcon">{{ story.likes }}</a>
</span>
</div>
</li>
when forloop.counter%4==2 or 3 then this
<li>
<div class="thumb">
<a href="#"><img src="{{ STATIC_URL }}images/thumb.jpg" width="185" height="185" /></a>
</div>
<div class="thumbFooter">
<span class="view">
<a href="#" class="viewIcon">{{ story.views }}</a>
</span>
<span class="like">
<a href="#" class="likeIcon">{{ story.likes }}</a>
</span>
</div>
</li>
when forloop.counter%4==0 of for loop this should be executed
<li class="omega">
<div class="thumb">
<a href="#"><img src="{{ STATIC_URL }}images/thumb.jpg" width="185" height="185" /></a>
</div>
<div class="thumbFooter">
<span class="view">
<a href="#" class="viewIcon">{{ story.views }}</a>
</span>
<span class="like">
<a href="#" class="likeIcon">{{ story.likes }}</a>
</span>
</div>
</li>
<div class="clear"></div>
{% endfor %}
You can build your own custom filter
In the templatetags directory of your Django, add a file named ‘mod.py’. In that file add the following code:
In your template use the mod filter like this: