[Answered ]-Django newbie – varying template table style by day of the week

1👍

I think the best way to do this is use a specific class from date:

<tr {% if date.day|divisibleby:"2" %}class="date_even"{% else %}class="date_odd"{% endif %}>
    <td>something</td>
    <td>something else</td>
    <td>{{ date }}</td>
</tr>

And then with css do the rest

1👍

An alternative to divisibleby is to use cycle to just cycle through the classes:

{% for row in table %}
<tr class="{% cycle 'row_odd' 'row_even' %}">
...

Leave a comment