在你的 middleware.py 你应该有这个:
if asbool(full_stack):
# Handle Python exceptions
app = ErrorHandler(app, global_conf, **config['pylons.errorware'])
# Display error documents for 401, 403, 404 status codes (and
# 500 when debug is disabled)
if asbool(config['debug']):
app = StatusCodeRedirect(app)
else:
app = StatusCodeRedirect(app, [400, 401, 403, 404, 500])
它处理你的错误。但是如果您想在发生错误时发送电子邮件,您可以编写您在代码的关键部分调用的辅助函数,它将错误的详细信息发送到您的电子邮件,或者您可以重写此中间件(ErrorHandler)。
ofc 您也可以在现有的 ErrorHandler 中添加该辅助函数调用,但我不推荐它(修改现有库不是好的编程)。
该辅助函数的代码:
import turbomail
def send_mail(body, author,subject, to):
conf = {
'mail.on': True,
'mail.transport': 'smtp',
'mail.smtp.server': 'smtp.DOMAIN.SMT:25',
}
turbomail.interface.start(conf)
message = turbomail.Message(
author = author,
to = to,
subject = subject,
plain = body,
encoding = "utf-8"
)
message.send()
turbomail.interface.stop()
希望能帮助到你...