List of Builtin Tests

callable()even()le()none()string()
defined()ge()lower()number()undefined()
divisibleby()gt()lt()odd()upper()
eq()in()mapping()sameas()
escaped()iterable()ne()sequence()
  • callable(obj, /)
  • Return whether the object is callable (i.e., some kind of function).

Note that classes are callable, as are instances of classes with acall() method.

  • defined(value)
  • Return true if the variable is defined:
  1. {% if variable is defined %}
  2. value of variable: {{ variable }}
  3. {% else %}
  4. variable is not defined
  5. {% endif %}

See the default() filter for a simple way to set undefinedvariables.

  • divisibleby(value, num)
  • Check if a variable is divisible by a number.
  • eq(a, b, /)
  • Same as a == b.

    • Aliases
    • ==, equalto
  • escaped(value)
  • Check if the value is escaped.
  • even(value)
  • Return true if the variable is even.
  • ge(a, b, /)
  • Same as a >= b.

    • Aliases
    • >=
  • gt(a, b, /)
  • Same as a > b.

    • Aliases
    • >, greaterthan
  • in(value, seq)
  • Check if value is in seq.

New in version 2.10.

  • iterable(value)
  • Check if it’s possible to iterate over an object.
  • le(a, b, /)
  • Same as a <= b.

    • Aliases
    • <=
  • lower(value)
  • Return true if the variable is lowercased.
  • lt(a, b, /)
  • Same as a < b.

    • Aliases
    • <, lessthan
  • mapping(value)
  • Return true if the object is a mapping (dict etc.).

Changelog

New in version 2.6.

  • ne(a, b, /)
  • Same as a != b.

    • Aliases
    • !=
  • none(value)
  • Return true if the variable is none.
  • number(value)
  • Return true if the variable is a number.
  • odd(value)
  • Return true if the variable is odd.
  • sameas(value, other)
  • Check if an object points to the same memory address than anotherobject:
  1. {% if foo.attribute is sameas false %}
  2. the foo attribute really is the `False` singleton
  3. {% endif %}
  • sequence(value)
  • Return true if the variable is a sequence. Sequences are variablesthat are iterable.
  • string(value)
  • Return true if the object is a string.
  • undefined(value)
  • Like defined() but the other way round.
  • upper(value)
  • Return true if the variable is uppercased.