Since v2.7 there is selectattr
:
Filters a sequence of objects by applying a test to the specified attribute of each object, and only selecting the objects with the test succeeding.
If no test is specified, the attribute’s value will be evaluated as a boolean.
Example usage:
{{ users|selectattr("is_active") }} {{ users|selectattr("email", "none") }}
Similar to a generator comprehension such as:
(u for user in users if user.is_active) (u for user in users if test_none(user.email))
See docs.