django模板 实现奇偶分行

<!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>

 实现如下:

原文地址:https://www.cnblogs.com/IPYQ/p/5784655.html