Reputation: 29569
In Django/Python, how do I catch a specific mySQL error: 'IntegrityError':
try:
cursor.execute(sql)
except IntegrityError:
do_something
Not sure what I should import and from where.
Upvotes: 2
Views: 3442
Reputation: 440
Here is a similar response . In summary
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})
Upvotes: 0