找回密码
 立即注册

模板设计者文档

2022-2-22 23:49| 发布者: 笨鸟自学网| 查看: 12090| 评论: 0

摘要: 这份文档描述了模板引擎中的语法和语义结构,对于创建 Jinja 模板是一份相当有用 的参考。因为模板引擎非常灵活,应用中的配置会在分隔符和未定义值的行为方面与 这里的配置有细微差异。概要模板仅仅是文本文件。它 ...


内置测试清单

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.

equalto(valueother)

Check if an object has the same value as another object:

{% if foo.expression is equalto 42 %}
    the foo attribute evaluates to the constant 42
{% endif %}

This appears to be a useless test as it does exactly the same as the == operator, but it can be useful when used together with the selectattr function:

{{ users|selectattr("email", "equalto", "foo@bar.invalid") }}

New in version 2.8.

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.


上一篇:沙箱下一篇:扩展

Archiver|手机版|笨鸟自学网 ( 粤ICP备20019910号 )

GMT+8, 2025-8-31 12:29 , Processed in 0.015453 second(s), 18 queries .

Powered by Discuz! X3.5

© 2001-2017 Discuz Team. Template By 【未来科技】【 www.wekei.cn 】

返回顶部