class DictLoader(BaseLoader): (source)
Loads a template from a Python dict mapping template names to template source. This loader is useful for unittesting: >>> loader = DictLoader({'index.html': 'source here'}) Because auto reloading is rarely useful this is disabled per default.
Method | __init__ |
Undocumented |
Method | get |
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. |
Method | list |
Iterates over all templates. If the loader does not support that it should raise a :exc:`TypeError` which is the default behavior. |
Instance Variable | mapping |
Undocumented |
Inherited from BaseLoader
:
Method | load |
Loads a template. This method looks up the template in the cache or loads one by calling :meth:`get_source`. Subclasses should not override this method as loaders working on collections of other loaders (such as :class:`PrefixLoader` or :class:`ChoiceLoader`) will not call this method but `get_source` directly. |
Class Variable | has |
Undocumented |
jinja2.loaders.BaseLoader.get_source
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 a string. 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.
Parameters | |
environment:Environment | Undocumented |
template:str | Undocumented |
Returns | |
t.Tuple[ | Undocumented |