内置测试清单

callable(object)

Return whether the object is callable (i.e., some kind of function). Note that classes are callable, as are instances with a call() method.

defined(value)

Return true if the variable is defined:

{% if variable is defined %}
    value of variable: {{ variable }}
{% else %}
    variable is not defined
{% endif %}

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

divisibleby(valuenum)

Check if a variable is divisible by a number.

escaped(value)

Check if the value is escaped.

even(value)

Return true if the variable is even.

iterable(value)

Check if it’s possible to iterate over an object.

lower(value)

Return true if the variable is lowercased.

mapping(value)

Return true if the object is a mapping (dict etc.).

New in version 2.6.

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(valueother)

Check if an object points to the same memory address than another object:

{% if foo.attribute is sameas false %}
    the foo attribute really is the `False` singleton
{% endif %}

sequence(value)

Return true if the variable is a sequence. Sequences are variables that 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.

文章导航