I’m looking for short conditional statement in python/django templates, so I could write less and reuse more. Something like (tkey in disabled_rows) ? “disabled-row” : “”.
Here’s what I’m doing:
{% if tkey in disabled_rows %}
<tr class="disabled-row">
{% else %}
<tr>
{% endif %}
I also tried a custom template tag without success:
{{ (tkey in disabled_rows)|xif:'true,false' }}
xif implementation:
def xif(cond, args):
if cond:
return args.split(',')[0]
else:
return args.split(',')[1]
Extra points if you can explain why this is not implemented natively in python.
For the example you gave, this solution is short and simple:
Perhaps there is something else you’re trying to achieve that would be better elucidated with a different example?