Django:捕获完整性错误并使用模板显示自定义消息

Django:捕获完整性错误并使用模板显示自定义消息,第1张

Django:捕获完整性错误并使用模板显示自定义消息

只需尝试并抓住。

from django.db import IntegrityErrorfrom django.shortcuts import render_to_responsetry:    # pre that produces errorexcept IntegrityError as e:    return render_to_response("template.html", {"message": e.message})

如果需要,可以在模板中使用该消息。

编辑

感谢吉尔-爵Vie的,你应该使用

e.__cause__
,因为这里描述。



欢迎分享,转载请注明来源:内存溢出

原文地址: https://www.outofmemory.cn/zaji/5647743.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-16
下一篇 2022-12-16

发表评论

登录后才能评论

评论列表(0条)

保存