[Answered ]-How to conditionally apply a template filter in Django?

1👍

You can work with a {% with … %} … {% endwith %} template tag:

{% with somevar=some.long.expression.with.stuff %}
<div><b>{% if my_condition %}{{ somevar|filter1 }}{% else %}{{ somevar }}{% endif %}</b></div>
{% endwith %}

Leave a comment