OpenQuizz
Une application de gestion des contenus pédagogiques
FileSystemLoader Class Reference
Inheritance diagram for FileSystemLoader:
Collaboration diagram for FileSystemLoader:

Public Member Functions

def __init__ (self, searchpath, encoding="utf-8", followlinks=False)
 
def get_source (self, environment, template)
 
def list_templates (self)
 
- Public Member Functions inherited from BaseLoader
def load (self, environment, name, globals=None)
 

Data Fields

 searchpath
 
 encoding
 
 followlinks
 

Additional Inherited Members

- Static Public Attributes inherited from BaseLoader
 has_source_access
 

Detailed Description

Loads templates from the file system.  This loader can find templates
in folders on the file system and is the preferred way to load them.

The loader takes the path to the templates as string, or if multiple
locations are wanted a list of them which is then looked up in the
given order::

>>> loader = FileSystemLoader('/path/to/templates')
>>> loader = FileSystemLoader(['/path/to/templates', '/other/path'])

Per default the template encoding is ``'utf-8'`` which can be changed
by setting the `encoding` parameter to something else.

To follow symbolic links, set the *followlinks* parameter to ``True``::

>>> loader = FileSystemLoader('/path/to/templates', followlinks=True)

.. versionchanged:: 2.8
   The ``followlinks`` parameter was added.

Constructor & Destructor Documentation

◆ __init__()

def __init__ (   self,
  searchpath,
  encoding = "utf-8",
  followlinks = False 
)

Member Function Documentation

◆ get_source()

def get_source (   self,
  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.

Reimplemented from BaseLoader.

◆ list_templates()

def list_templates (   self)
Iterates over all templates.  If the loader does not support that
it should raise a :exc:`TypeError` which is the default behavior.

Reimplemented from BaseLoader.

Field Documentation

◆ encoding

encoding

◆ followlinks

followlinks

◆ searchpath

searchpath

The documentation for this class was generated from the following file: