from django.db import IntegrityError
except IntegrityError:
This is what you need.
EDITED for @mbrochh:
from django.db import IntegrityError
except IntegrityError as e:
if 'unique constraint' in e.message: # or e.args[0] from Django 1.10
#do something
Yes, you can be more precise but in question case UNIQUE failed
is highly likely.