开发者

Running quick if statements in Django template language

开发者 https://www.devze.com 2023-03-27 10:03 出处:网络
I\'m using this code: <div class=\"stream {% if streams.online %}online{% else %}offline{% endif %}\">

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

精彩评论

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