@register.filter def highlight(text, word): return mark_safe(text.replace(word, "<span class='highlight'>%s</span>" % word))