Jinja2 shorthand conditional

后端 未结 2 1821
温柔的废话
温柔的废话 2020-12-23 08:36

Say I have this:

{% if files %}
    Update
{% else %}
    Continue
{% endif %}

In PHP, say, I can write a shorthand conditional, like:

2条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-23 09:20

    Yes, it's possible to use inline if-expressions:

    {{ 'Update' if files else 'Continue' }}
    

提交回复
热议问题