Just use try and catch.
from django.db import IntegrityError
from django.shortcuts import render_to_response
try:
# code that produces error
except IntegrityError as e:
return render_to_response("template.html", {"message": e.message})
If you want you can use the message in your template.
EDIT
Thanks for Jill-Jênn Vie, you should use e.__cause__
, as described here.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…