Active link

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
import re

from django import template
from django.core.urlresolvers import get_resolver

register = template.Library()

@register.simple_tag
def current(request, view):
    possible_results = get_resolver(None).reverse_dict.getlist(view)

    if len(possible_results) != 0 and re.match(possible_results[0][1], request.path[1:]):
        return 'current'
    return ''

More like this

  1. Active page class for selected menu items by kunitoki 1 year, 6 months ago
  2. load m2m fields objects by dirol 3 years, 10 months ago
  3. Pagination Alphabetically compatible with paginator_class by vascop 2 years ago
  4. Active class for navigation link by cschand 4 years, 7 months ago
  5. Using reverse() to do redirects by ubernostrum 6 years, 8 months ago

Comments

(Forgotten your password?)