You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
20 lines
447 B
Python
20 lines
447 B
Python
8 years ago
|
import re
|
||
|
|
||
|
from django import template
|
||
|
from django.core.urlresolvers import reverse, NoReverseMatch
|
||
|
|
||
|
register = template.Library()
|
||
|
|
||
|
|
||
|
@register.simple_tag(takes_context=True)
|
||
|
def active(context, pattern_or_urlname):
|
||
|
try:
|
||
|
pattern = '^' + reverse(pattern_or_urlname)
|
||
|
except NoReverseMatch:
|
||
|
pattern = pattern_or_urlname
|
||
|
path = context['request'].path
|
||
|
if re.search(pattern, path):
|
||
|
return 'active'
|
||
|
return ''
|
||
|
|