找回密码
 立即注册

扩展

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

摘要: Jinja2 支持扩展来添加过滤器、测试、全局变量或者甚至是处理器。扩展的主要动力是 把诸如添加国际化支持的常用代码迁移到一个可重用的类。添加扩展扩展在 Jinja2 环境创建时被添加。一旦环境被创建,就不能添加额外 ...


classjinja2.nodes.Expr

Baseclass for all expressions.

Node type:Node
as_const(eval_ctx=None)

Return the value of the expression as constant or raise Impossible if this was not possible.

An EvalContext can be provided, if none is given a default context is created which requires the nodes to have an attached environment.

Changed in version 2.4: the eval_ctx parameter was added.

can_assign()

Check if it’s possible to assign something to this node.

classjinja2.nodes.BinExpr(left, right)

Baseclass for all binary expressions.

Node type:Expr
classjinja2.nodes.Add(left, right)

Add the left to the right node.

Node type:BinExpr
classjinja2.nodes.And(left, right)

Short circuited AND.

Node type:BinExpr
classjinja2.nodes.Div(left, right)

Divides the left by the right node.

Node type:BinExpr
classjinja2.nodes.FloorDiv(left, right)

Divides the left by the right node and truncates conver the result into an integer by truncating.

Node type:BinExpr
classjinja2.nodes.Mod(left, right)

Left modulo right.

Node type:BinExpr
classjinja2.nodes.Mul(left, right)

Multiplies the left with the right node.

Node type:BinExpr
classjinja2.nodes.Or(left, right)

Short circuited OR.

Node type:BinExpr
classjinja2.nodes.Pow(left, right)

Left to the power of right.

Node type:BinExpr
classjinja2.nodes.Sub(left, right)

Subtract the right from the left node.

Node type:BinExpr
classjinja2.nodes.Call(node, args, kwargs, dyn_args, dyn_kwargs)

Calls an expression. args is a list of arguments, kwargs a list of keyword arguments (list of Keyword nodes), and dyn_args and dyn_kwargs has to be either None or a node that is used as node for dynamic positional (*args) or keyword (**kwargs) arguments.

Node type:Expr
classjinja2.nodes.Compare(expr, ops)

Compares an expression with some other expressions. ops must be a list of Operands.

Node type:Expr
classjinja2.nodes.Concat(nodes)

Concatenates the list of expressions provided after converting them to unicode.

Node type:Expr
classjinja2.nodes.CondExpr(test, expr1, expr2)

A conditional expression (inline if expression). ({{ foo if bar else baz }})

上一篇:模板设计者文档下一篇:集成

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

GMT+8, 2026-10-31 19:12 , Processed in 0.023514 second(s), 18 queries .

© 2001-2020