FunctionLoader Class

Inheritance diagram of FunctionLoader

class FunctionLoader(load_func)

A loader that is passed a function which does the loading. The function becomes the name of the template passed and has to return either an unicode string with the template source, a tuple in the form (source, filename, uptodatefunc) or None if the template does not exist.

>>> def load_template(name):
...     if name == 'index.html':
...         return '...'
>>> loader = FunctionLoader(load_template)

The uptodatefunc is a function that is called if autoreload is enabled and has to return True if the template is still up to date. For more details have a look at BaseLoader.get_source() which has the same return value.


get_source(environment, template)
list_templates() Iterates over all templates.
load(environment, name[, globals]) Loads a template.


has_source_access bool(x) -> bool


class FunctionLoader

Method details

get_source(environment, template)

Inherited member details


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

load(environment, name, globals=None)

Loads a template. This method looks up the template in the cache or loads one by calling get_source(). Subclasses should not override this method as loaders working on collections of other loaders (such as PrefixLoader or ChoiceLoader) will not call this method but get_source directly.

has_source_access = True

Table Of Contents

Previous topic

FileSystemLoader Class

Next topic

ModuleLoader Class