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" }}">
精彩评论