Reputation: 605
I thought it would be neat to pick up a Duplicate entry exception and display the specific field witch caused the error to the user.
Example exception:
"Duplicate entry '[email protected]' for key 'email'"
Displaying: "email already in use"
But I can't seem to find a way to extract the the key 'email' (or whatever causes the exception) from the exception.
Thanks in advance
Upvotes: 1
Views: 1291
Reputation: 122436
That's because the exception comes from the database, not from within Django. Django is just passing it along. So the error message isn't parsed for content or composed out of other values.
If you want to extract the email address you'll need to parse the string for the details that you want.
Upvotes: 1