Comparisons

Like most languages, Jinja2 comes equipped with the standard set of comparison expressions you would expect, which will render a Boolean true or false.

The expressions in Jinja2 are as follows:

Expression Definition
== True if two objects are equal
!= True if two objects are not equal
> True if the left-hand side is greater than the right-hand side
< True if the left-hand side is less than the right- hand side
>= True if the left-hand side is greater than, or equal to the right-hand side
<= True if the left-hand side is less than, or equal to the right-hand side

 

If you have written comparison operations in almost any other programming language (usually in the form of an if statement), these should all seem very familiar. Jinja2 maintains this functionality in templates, allowing for the same powerful comparison operations you would expect in conditional logic from any good programming language.