jinja2 中嵌套变量的默认值
Default value for nested variables in jinja2
如果 output
不存在,这将出错:
result.output == false # error: dict has no attribute 'output'
所以我必须使用默认值:
result.output | default(false) == false
但是我如何处理两个级别中不存在的 output
(空合并问题):
result.output.something == false # error: dict has no attribute 'output'
@β.ειοιτ.βε 上述评论的修改版本:
result.output is defined
and result.output.something |default(false) == false
如果 output
不存在,这将出错:
result.output == false # error: dict has no attribute 'output'
所以我必须使用默认值:
result.output | default(false) == false
但是我如何处理两个级别中不存在的 output
(空合并问题):
result.output.something == false # error: dict has no attribute 'output'
@β.ειοιτ.βε 上述评论的修改版本:
result.output is defined
and result.output.something |default(false) == false