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
| Attribute | Type | Description |
|---|---|---|
| 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
| Name | Type | Description |
|---|---|---|
| engine | object | The 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
| Name | Type | Description |
|---|---|---|
| template_name | string | The logical name or path of the template to be retrieved |
| skip | list = None | A collection of Origin objects to ignore during the search to prevent infinite recursion loops |
Returns
| Type | Description |
|---|---|
[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
| Name | Type | Description |
|---|---|---|
| template_name | string | The name of the template for which to generate potential source origins |
Returns
| Type | Description |
|---|---|
iterator | An 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).