class FileSystemLoader(BaseLoader):
Load templates from a directory in the file system.
The path can be relative or absolute. Relative paths are relative to the current working directory.
loader = FileSystemLoader("templates")
A list of paths can be given. The directories will be searched in order, stopping at the first matching template.
loader = FileSystemLoader(["/override/templates", "/default/templates"])
Parameters | |
searchpath | A path, or list of paths, to the directory that contains the templates. |
encoding | Use this encoding to read the text from template files. |
followlinks | Follow symbolic links in the path. |
Method | __init__ |
Undocumented |
Method | get_source |
No summary |
Method | list_templates |
Iterates over all templates. If the loader does not support that it should raise a TypeError which is the default behavior. |
Instance Variable | encoding |
Undocumented |
Instance Variable | followlinks |
Undocumented |
Instance Variable | searchpath |
Undocumented |
Inherited from BaseLoader
:
Method | load |
No summary |
Class Variable | has_source_access |
Undocumented |
Undocumented
Parameters | |
searchpath:t.Union[ | Undocumented |
encoding:str | Undocumented |
followlinks:bool | 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 |
jinja2.loaders.BaseLoader.list_templates
TypeError
which is the default behavior.Returns | |
t.List[ | Undocumented |