异常

最后更新于:2022-04-01 04:03:20

*exception *jinja2.TemplateError(*message=None*)[](http://docs.jinkan.org/docs/jinja2/api.html#jinja2.TemplateError "Permalink to this definition") Baseclass for all template errors. *exception *jinja2.UndefinedError(*message=None*)[](http://docs.jinkan.org/docs/jinja2/api.html#jinja2.UndefinedError "Permalink to this definition") Raised if a template tries to operate on [Undefined](http://docs.jinkan.org/docs/jinja2/api.html#jinja2.Undefined "jinja2.Undefined"). *exception *jinja2.TemplateNotFound(*name*, *message=None*)[](http://docs.jinkan.org/docs/jinja2/api.html#jinja2.TemplateNotFound "Permalink to this definition") Raised if a template does not exist. *exception *jinja2.TemplatesNotFound(*names=()*, *message=None*)[](http://docs.jinkan.org/docs/jinja2/api.html#jinja2.TemplatesNotFound "Permalink to this definition") Like [TemplateNotFound](http://docs.jinkan.org/docs/jinja2/api.html#jinja2.TemplateNotFound "jinja2.TemplateNotFound") but raised if multiple templates are selected. This is a subclass of [TemplateNotFound](http://docs.jinkan.org/docs/jinja2/api.html#jinja2.TemplateNotFound "jinja2.TemplateNotFound") exception, so just catching the base exception will catch both. New in version 2.2. *exception *jinja2.TemplateSyntaxError(*message*, *lineno*, *name=None*,*filename=None*)[](http://docs.jinkan.org/docs/jinja2/api.html#jinja2.TemplateSyntaxError "Permalink to this definition") Raised to tell the user that there is a problem with the template. message[](http://docs.jinkan.org/docs/jinja2/api.html#jinja2.TemplateSyntaxError.message "Permalink to this definition") 错误信息的 utf-8 字节串。 lineno[](http://docs.jinkan.org/docs/jinja2/api.html#jinja2.TemplateSyntaxError.lineno "Permalink to this definition") 发生错误的行号。 name[](http://docs.jinkan.org/docs/jinja2/api.html#jinja2.TemplateSyntaxError.name "Permalink to this definition") 模板的加载名的 unicode 字符串。 filename[](http://docs.jinkan.org/docs/jinja2/api.html#jinja2.TemplateSyntaxError.filename "Permalink to this definition") 加载的模板的文件名字节串,以文件系统的编码(多是 utf-8 , Windows 是 mbcs )。 文件名和错误消息是字节串而不是 unicode 字符串的原因是,在 Python 2.x 中,不对异常和回溯使用 unicode ,编译器同样。这会在 Python 3 改变。 *exception *jinja2.TemplateAssertionError(*message*, *lineno*, *name=None*,*filename=None*)[](http://docs.jinkan.org/docs/jinja2/api.html#jinja2.TemplateAssertionError "Permalink to this definition") Like a template syntax error, but covers cases where something in the template caused an error at compile time that wasn’t necessarily caused by a syntax error. However it’s a direct subclass of [TemplateSyntaxError](http://docs.jinkan.org/docs/jinja2/api.html#jinja2.TemplateSyntaxError "jinja2.TemplateSyntaxError") and has the same attributes.
';