Handling user creation errors
Let's improve the signup form to handle some errors.
Checking whether passwords do not match
What happens if password1
doesn't match password2
? To handle such an error, we add the following else
block in bold in /accounts/views.py
:
… def signupaccount(request): if request.method == 'GET': return render(request, 'signupaccount.html', {'form':UserCreationForm}) else: if request.POST['password1'] == request.POST['password2']: user = User.objects.create_user( ...