Jinja2 shorthand conditional

后端 未结 2 1822
温柔的废话
温柔的废话 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:09

    Alternative way (but it's not python style. It's JS style)

    {{ files and 'Update' or 'Continue' }}
    
    0 讨论(0)
  • 2020-12-23 09:20

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

    {{ 'Update' if files else 'Continue' }}
    
    0 讨论(0)
提交回复
热议问题