Django template CSS – Display rows with alternate colors

Here’s a snippet to print rows in Django template with alternate colors. Assume you have 2 CSS styles for rows:

.row1 {
    background: #EDF3FE;
}
.row2 {
    background: white;
}

Template code:

{% for row in dataset %}
	<tr class="{% cycle "row1" "row2" %}">
		<td>{{row.customer}}</td>
		<td>{{row.sfid}}</td>
		<td>{{row.package}}</td>
		<td>{{row.support_expires}}</td>
	</tr>
{% endfor %}
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s