Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to negate test in jinja2

Tags:

jinja2

I can filter a list in jinja using selectattr, for example if I want the elements for which foo is None:

lists | selectattr('foo','none')

but how can I negate this? How can I get all elements for which foo is not none?

like image 505
Nathan Avatar asked Nov 14 '16 13:11

Nathan


People also ask

What is block content in Jinja?

All the block tag does is tell the template engine that a child template may override those placeholders in the template. In your example, the base template (header. html) has a default value for the content block, which is everything inside that block. By setting a value in home.


1 Answers

{{ lists | rejectattr('foo', 'none') }}

http://jinja.pocoo.org/docs/dev/templates/#rejectattr

like image 185
dizzyf Avatar answered Sep 28 '22 08:09

dizzyf