django activate link/button if the path startes with `<path>`

Viewed 20

I'm building a Django app and I have a link on my navbar that I want to activate it(means add a css class) if the path starts with <base_url>/accounts/

I tried the following and it doesn't work

{% url 'accounts:profile' as pro %}
{% url 'accounts:setting' as set %}
{% url 'accounts:anotherpage' as ano %}

This doesn't work
{% if request.path == pro or request.path == set or request.path == ano %} active {% endif %}
1 Answers

This should solve your ask:

{% if pro in request.path or set in request.path or ano in request.path %} active {% endif %}

but if you want

I want to activate it if the path starts with <base_url>/accounts/

in this case:

{% if '/accounts/' in request.path %} active {% endif %}
Related