[Django]-Django: what kind of exceptions does create_user throw?

7๐Ÿ‘

โœ…

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:

  • if username is valid, match with the regex e.g. \w+
  • check if username is already taken or not e.g. User.objects.filter(username=username).exists()
  • check if email is already used for an account e.g. User.objects.filter(email=email).exists()
  • then create the user

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.

๐Ÿ‘คAamir Rind

0๐Ÿ‘

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.

๐Ÿ‘คaemdy

Leave a comment