Django模板中是否可以使用aList中的元素?

问题描述:

如果[a,b,c]中的a,就像python

Does something like the python

if "a" in ["a", "b", "c"]:
    pass

存在于Django模板中?

exist in Django templates?

如果没有,是否有简单的方法来实现?

If not, is there an easy way to implement it?

p>这是您通常在查看函数中执行的操作。

This is something you usually do in your view functions.

aList = ["a", "b", "c"]
listAndFlags = [ (item,item in aList) for item in someQuerySet ]

现在您有一个简单的双元素列表,您可以显示

Now you have a simple two-element list that you can display

{% for item, flag in someList %}
    <tr><td class="{{flag}}">{{item}}</td></tr>
{% endfor %}