|
|
None | __init__ (self, t.Union[str, "os.PathLike[str]", t.Sequence[t.Union[str, "os.PathLike[str]"]]] searchpath, str encoding="utf-8", bool followlinks=False) |
| |
| t.Tuple[str, str, t.Callable[[], bool]] | get_source (self, "Environment" environment, str template) |
| |
| t.List[str] | list_templates (self) |
| |
| "Template" | load (self, "Environment" environment, str name, t.Optional[t.MutableMapping[str, t.Any]] globals=None) |
| |
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.
.. code-block:: python
loader = FileSystemLoader("templates")
A list of paths can be given. The directories will be searched in
order, stopping at the first matching template.
.. code-block:: python
loader = FileSystemLoader(["/override/templates", "/default/templates"])
:param searchpath: A path, or list of paths, to the directory that
contains the templates.
:param encoding: Use this encoding to read the text from template
files.
:param followlinks: Follow symbolic links in the path.
.. versionchanged:: 2.8
Added the ``followlinks`` parameter.
| t.Tuple[str, str, t.Callable[[], bool]] jinja2.loaders.FileSystemLoader.get_source |
( |
|
self, |
|
|
"Environment" |
environment, |
|
|
str
|
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 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.
Reimplemented from jinja2.loaders.BaseLoader.
Reimplemented in sphinx.jinja2glue.SphinxFileSystemLoader.