Reputation: 301
I want to catch them and return helpful messages to the user. The documentation https://docs.djangoproject.com/en/1.4/topics/auth/ says ValueError is raised when given an invalid username. There's also IntegrityError, when the username already exists. Are these all?
Is this the usual way to do it?
Upvotes: 3
Views: 2773
Reputation: 3802
You can always take a look at source code easily since their moved to Github or find it in Python site-packages
directory on your machine.
Just go to django/contrib/auth/
and analyze some code.
Upvotes: 0
Reputation: 39689
If you are not using Django Auth Forms then you have to do the validation manually. The simple way is when user submit the custom form you should check:
User.objects.filter(username=username).exists()
User.objects.filter(email=email).exists()
FYI: there are some already Django Auth packages e.g. django-allauth, django-userena and many more which handles all the stuff pretty well, instead of reinventing the wheel by your self.
Upvotes: 7