开发者

Running quick if statements in Django template language

I'm using this code:

<div class="stream {% if streams.online %}online{% else %}offline{% endif %}">

It seems a little redundant. I'd love to run this code

<div class="stream {开发者_JAVA技巧{ 'online' if stream.online else 'offline' }}">

But sadly that doesn't work. Is there a shorter and less messy way of doing what I want?


Can't you use the yesno built-in template filter?

As in,

<div class="stream {{ stream.online|yesno:"online,offline" }}">
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜