Exceptions

  • exception jinja2.TemplateError(message=None)
  • Baseclass for all template errors.
  • exception jinja2.UndefinedError(message=None)
  • Raised if a template tries to operate on Undefined.
  • exception jinja2.TemplateNotFound(name, message=None)
  • Raised if a template does not exist.
  • exception jinja2.TemplatesNotFound(names=(), message=None)
  • Like TemplateNotFound but raised if multiple templatesare selected. This is a subclass of TemplateNotFoundexception, so just catching the base exception will catch both.

Changelog

New in version 2.2.

  • exception jinja2.TemplateSyntaxError(message, lineno, name=None, filename=None)
  • Raised to tell the user that there is a problem with the template.

    • message
    • The error message as utf-8 bytestring.

    • lineno

    • The line number where the error occurred

    • name

    • The load name for the template as unicode string.

    • filename

    • The filename that loaded the template as bytestring in the encodingof the file system (most likely utf-8 or mbcs on Windows systems).

The reason why the filename and error message are bytestrings and notunicode strings is that Python 2.x is not using unicode for exceptionsand tracebacks as well as the compiler. This will change with Python 3.

  • exception jinja2.TemplateRuntimeError(message=None)
  • A generic runtime error in the template engine. Under some situationsJinja may raise this exception.
  • exception jinja2.TemplateAssertionError(message, lineno, name=None, filename=None)
  • Like a template syntax error, but covers cases where something in thetemplate caused an error at compile time that wasn’t necessarily causedby a syntax error. However it’s a direct subclass ofTemplateSyntaxError and has the same attributes.