template_exists.py 311 Bytes
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13
from django import template
from django.template.defaultfilters import stringfilter

register = template.Library()

@register.filter
@stringfilter
def template_exists(value):
    try:
        template.loader.get_template(value)
        return True
    except template.TemplateDoesNotExist:
        return False