python - how do catch A 'UNIQUE constraint failed' 404 in django - Stack Overflow

PHOTO EMBED

Tue Jun 14 2022 08:43:05 GMT+0000 (Coordinated Universal Time)

Saved by @arielvol #python

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
content_copyCOPY

https://stackoverflow.com/questions/27729487/how-do-catch-a-unique-constraint-failed-404-in-django