I was wondering if there was a ternary operator (condition ? true-value : false-value) that could be used in a Django template. I see there is a python one (true-value if c
I've just implemented the ternary operator for Django as a tag, see https://github.com/alexei/django-template-extensions You can use it as:
{% ?: exp1 exp2 exp3 %}
{% ?: exp1 exp2 %}
Or:
{% iif exp1 exp2 exp3 %}
{% iif exp1 exp2 %}
I figured out that it makes more sense than the yesno
filter, even though it's really not that Pythonic.