如何过滤 jinja2 模板中的集合?

How do I filter a collection in a jinja2 template ?

我有一组命名元组,如下所示:

[('mountpoint=X',state='UP'),(mountpoint='Y',state='DOWN'),(mountpoint='Z',state='DOWN'...)]

我将此集合传递给我的一个模板。我想根据状态过滤该集合。尝试了以下无济于事

  {% for state in states|selectattr('state','down') %}
TemplateRuntimeError: no test named 'down'

  {% for state in states|selectattr(state='down') %}
FilterArgumentError: Missing parameter for attribute name

  {% for state in states|select(state='down') %}
No error, but doesn't filter at all.

使用equalto测试:

{% for state in states|selectattr('state', 'equalto', 'down') %}