Alternate row colors in App Engine
Posted on October 20th, 2008 in App Engine, Google, Programming |
You have a senario where you need to have alternating colors in each rows of data in app engine or django, how can you achieve this? Here is a simple solution on doing it (This took me more than 30 mins to find out the solution coz most of the time they will give you php’s solution on alternating rows)
{% for video in videos %}
<div class="row {% cycle odd,even %}">
{{ video.title }}
<div class="youtubeLink">
<a href="{{ video.youtube_id }}">
{{ video.youtube_id }}
</a>
</div>
</div>
{% endfor %}
The main solution is this code
{% cycle odd,even %}
What this do is that it cycles around each row and returns the right index (odd or even). And with this function you are not bound to just 2 selections, if you want more you could just do something like
{% cycle one,two,three,four %}
Hope this helps.












