<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>play</title>
</head>
<body>
<h1>Welcome to oldboy shopping mall,play center ..</h1>
<ul>{% for user in users %}
{#% if user.username == "alex2" %#}
{#% if forloop.counter > 2 %#}
{% if forloop.counter|divisibleby:“2” %} # 判断如果循环索引奇偶行数
<li style="background-color: red">username:{{ user.username }},name:{{user.name }}</li>
{% else %}
<li style="background-color: green">username:{{ user.username }},name:{{user.name }}</li>
{% endif %}
{% endfor %}
</ul> </body>
</html>
实现如下: