Reputation: 145
I am new to django and am trying to only render text which does not have the word 'After' or 'Before' in it. However this didnt break anything but it didnt actually remove those values?
I looked at using a regex but this really isnt recommended for django templates.
{% if "After" not in window.name or "Before" not in window.name %}
{{window.event_id}}-{{window.name}}
{% endif %}
The codebase I am working on makes it almost impossible to remove these values in the models before you get to the template... I can only apologise for maintaining and putting up with this!
Upvotes: 0
Views: 237
Reputation: 83
The problem is that your condition is always true.
Here's one way to do it. Probably not the most ideal.
{% if "After" in window.name or "Before" in window.name %}
{% else %}
{{window.event_id}}-{{window.name}}
{% endif %}
This way it only prints if neither 'Before' or 'After' is in the string. I didn't test this code but hopefully you get the idea.
Upvotes: 1