Skip to main content

Loader

This class provides a base interface for loading template files from various sources. It handles the logic for iterating through potential template origins, retrieving content, and instantiating template objects while preventing infinite recursion during template extension. Subclasses are expected to implement specific source-finding logic by overriding the template source iterator.

Attributes

AttributeTypeDescription
engine[Engine](../../engine/engine.md?sid=django_template_engine_engine)The template engine instance used to initialize and configure the loader's template processing behavior.

Constructor

Signature

def Loader(
engine: object
) - > null

Parameters

NameTypeDescription
engineobjectThe template engine instance to be used by the loader.

Methods


get_template()

@classmethod
def get_template(
template_name: string,
skip: list = None
) - > [Template](../../base/template.md?sid=django_template_base_template)

Call self.get_template_sources() and return a Template object for the first template matching template_name. If skip is provided, ignore template origins in skip. This is used to avoid recursion during template extending.

Parameters

NameTypeDescription
template_namestringThe logical name or path of the template to be retrieved
skiplist = NoneA collection of Origin objects to ignore during the search to prevent infinite recursion loops

Returns

TypeDescription
[Template](../../base/template.md?sid=django_template_base_template)A Template object initialized with the source contents and origin metadata

get_template_sources()

@classmethod
def get_template_sources(
template_name: string
) - > iterator

An iterator that yields possible matching template paths for a template name.

Parameters

NameTypeDescription
template_namestringThe name of the template for which to generate potential source origins

Returns

TypeDescription
iteratorAn iterable yielding Origin objects representing potential locations for the template

reset()

@classmethod
def reset()

Reset any state maintained by the loader instance (e.g. cached templates or cached loader modules).