清理模板代码

时间:2015-06-14 23:00:21

标签: python django

有更好的方法来执行以下操作吗?也许像if/elif/else

{% if avail.allows_free_streaming %}Free to Stream{% endif %}
{% if avail.requires_paid_subscription %}Subscription{% endif %}
{% if not avail.requires_paid_subscription and not avail.allow_free_streaming %}N/A{% endif %}

1 个答案:

答案 0 :(得分:1)

是的,您可以使用以下方法:

{% if avail.allows_free_streaming %}
    Free to Stream
{% elif avail.requires_paid_subscription %}
    Subscription
{% else %}
    N/A
{% endif %}