Skip to content

Instantly share code, notes, and snippets.

@vitorfs
Last active August 23, 2023 05:44
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save vitorfs/7d9e2d2c48fab9d6f432717814e6b762 to your computer and use it in GitHub Desktop.
Save vitorfs/7d9e2d2c48fab9d6f432717814e6b762 to your computer and use it in GitHub Desktop.
Startswith Template Filter
{% load startswith %}
<li{% if request.path|startswith:'/settings/' %} class="active"{% endif %}>
from django import template
register = template.Library()
@register.filter('startswith')
def startswith(text, starts):
if isinstance(text, basestring):
return text.startswith(starts)
return False
@dartwlad
Copy link

dartwlad commented May 7, 2018

where i have to place "startswith.py" ?
pycharm can`t find it near admin.py, models.py and etc.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment