说我有这个:
{% if files %}
Update
{% else %}
Continue
{% endif %}
在 PHP 中,比如说,我可以编写简写条件,例如:
<?php echo $foo ? 'yes' : 'no'; ?>
有没有一种方法可以将其翻译为在 jinja2 模板中工作:
'yes' if foo else 'no'
是的,可以使用 内联 if 表达式:
{{ 'Update' if files else 'Continue' }}
另一种方式(但不是Python风格,而是JS风格)
{{ files and 'Update' or 'Continue' }}