只需尝试并抓住。
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__,因为这里描述。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)