import urllib.parse from django import template register = template.Library() @register.filter def urlsafe(h): return urllib.parse.quote(h, safe="")