I have this string doc.specalization.name from my views. If it does end with an s, I want to remove the s.
I tried this code but i get Could not parse the remainder: '('s')' from 'doc.specialization.name.endswith('s')'
{% if doc.specialization.name.endswith('s') %}
<h3> {{doc.specialization.name|slice:":-1"}} </h3>
{% endif %}
Karthikr's answer is close. Ifequal is scheduled to be deprecated in future versions of Django, so you may want to use the method below. You also need to add a ':' after the '-1'.
{% if doc.specialization.name|default:""|slice:"-1:" == "s" %}
<h3> {{ doc.specialization.name|slice:":-1" }} </h3>
{% else %}
<h3> {{ doc.specialization.name }} </h3>
{% endif %}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With