Django 模板中不区分大小写的字符串比较

Django-case insensitive string comparison in django template

如何进行不区分大小写的字符串比较?

在我的例子中,当 topic.title 等于 page.slug 时,我需要添加一个 class menu_active。但是,现在

所以我的条件不合格

nav_bar.html

{% for topic in landing_pages %}
     <li role="presentation">
<a class="{% if topic.title == page.slug %}menu_active{% endif %}" href="/{{topic.slug}}/">{{topic.title}}</a>
     </li>
{% endfor %}

通过内置模板标签传递字符串 lower/upper 然后进行比较。

<a class="{% if topic.title|lower == page.slug|lower %}menu_active{% endif %}