@register.filter def breadcrumbs(url): home = ['<li>you are here : <a href="/" title="Breadcrumb link to the homepage.">home</a> »</li>',] links = url.strip('/').split('/') bread = [] total = len(links)-1 for i, link in enumerate(links): if not link == '': bread.append(link) this_url = "/".join(bread) sub_link = re.sub('-', ' ', link) if not i == total: tlink = '<li><a href="/%s/" title="Breadcrumb link to %s">%s</a> »</li>' % (this_url, sub_link, sub_link) else: tlink = '<li>%s</li>' % sub_link home.append(tlink) bcrumb = "".join(home) return mark_safe(bcrumb)