Last active
October 22, 2024 17:00
-
-
Save vitorfs/7d9e2d2c48fab9d6f432717814e6b762 to your computer and use it in GitHub Desktop.
Startswith Template Filter
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{% load startswith %} | |
<li{% if request.path|startswith:'/settings/' %} class="active"{% endif %}> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django import template | |
register = template.Library() | |
@register.filter('startswith') | |
def startswith(text, starts): | |
if isinstance(text, basestring): | |
return text.startswith(starts) | |
return False |
For this case you just do this: {% if request.path_info|slice:"0:10" == "/settings/" %}
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
where i have to place "startswith.py" ?
pycharm can`t find it near admin.py, models.py and etc.