异常

  • 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.

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
    • 错误信息的 utf-8 字节串。

    • lineno

    • 发生错误的行号。

    • name

    • 模板的加载名的 unicode 字符串。

    • filename

    • 加载的模板的文件名字节串,以文件系统的编码(多是 utf-8 , Windows是 mbcs )。

文件名和错误消息是字节串而不是 unicode 字符串的原因是,在 Python 2.x中,不对异常和回溯使用 unicode ,编译器同样。这会在 Python 3 改变。

  • 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.