Last active
August 23, 2023 05:44
-
-
Save vitorfs/7d9e2d2c48fab9d6f432717814e6b762 to your computer and use it in GitHub Desktop.
Startswith Template Filter
This file contains 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 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@dartwlad
https://docs.djangoproject.com/en/2.2/howto/custom-template-tags/