ModuleLoader Class

Inheritance diagram of ModuleLoader

class ModuleLoader(path)

This loader loads templates from precompiled templates.

Example usage:

>>> loader = ChoiceLoader([
...     ModuleLoader('/path/to/compiled/templates'),
...     FileSystemLoader('/path/to/templates')
... ])

Templates can be precompiled with Environment.compile_templates().


get_source(environment, template) Get the template source, filename and reload helper for a template.
list_templates() Iterates over all templates.
load(environment, name[, globals])


has_source_access bool(x) -> bool


class ModuleLoader

Method details

static get_module_filename(name)
static get_template_key(name)
load(environment, name, globals=None)

Attribute details

has_source_access = False

Inherited member details

get_source(environment, template)

Get the template source, filename and reload helper for a template. It’s passed the environment and template name and has to return a tuple in the form (source, filename, uptodate) or raise a TemplateNotFound error if it can’t locate the template.

The source part of the returned tuple must be the source of the template as unicode string or a ASCII bytestring. The filename should be the name of the file on the filesystem if it was loaded from there, otherwise None. The filename is used by python for the tracebacks if no loader extension is used.

The last item in the tuple is the uptodate function. If auto reloading is enabled it’s always called to check if the template changed. No arguments are passed so the function must store the old state somewhere (for example in a closure). If it returns False the template will be reloaded.


Iterates over all templates. If the loader does not support that it should raise a TypeError which is the default behavior.

Table Of Contents

Previous topic

FunctionLoader Class

Next topic

PackageLoader Class