I've come across with different python ternary operators such as:
a if b else 0
but it didn't work when I tried to include it inside Django HTML template
{% a if b else 0 %}
Here is the exact code that I'll be using but won't work:
{% 'error' if form.title.errors else '' %}
or
{% form.title.errors ? 'error' : '' %}
I don't like to do the usual
{% if form.title.errors %}error{% endif %}
because it looks bulky in my opinion especially if I add an else statement.
Any suggestions? or should I just stick with it?
You can get more or less the behavior you want by using the
yesno
filter (documentation):