[Answered ]-Django: Get absolute file path of template file from template name, without parsing the template

1👍

Reverse engineered this from the python source code:

import os
from django import template

def find_template(template_name: str) -> str:
    for engine in template.engines.all():
        for loader in engine.engine.template_loaders:
            for origin in loader.get_template_sources(template_name):
                if os.path.exists(origin.name):
                    return origin.name
    raise template.TemplateDoesNotExist(f"Could not find template: {template_name}")

Leave a comment