from django import template from django.template.defaultfilters import stringfilter register = template.Library() @register.filter @stringfilter def media_url(value,MEDIA_URL): """Searches for {{ MEDIA_URL }} and replaces it with the current MEDIA_URL""" return value.replace('{{ MEDIA_URL }}', MEDIA_URL) media_url.is_safe = True