I want to be able to return a message to the user when they try to register but their registration fails.
I have tried all of the following methods:
try:
user = User.objects.create_user(username, email, password)
except User.DoesNotExist
print "aaaa"
try:
user = User.objects.create_user(username, email, password)
except IntegrityError
print "aaaa"
Of course, neither of the above work. How do I properly throw an exception?
I had the same problem some time ago, here’s my solution: