Django's default User model username validator allows testUser
and TestUser
for 2 different usernames.
I found a way to make username case insensitive during the registration but I am wondering if there's not a built-in way to do that.
Here is how I did it:
if form.is_valid():
username = form.cleaned_data['username']
brk = True
try:
User.objects.get(username__iexact=username)
except:
brk = False
if brk:
messages.warning(request, 'Username already in use')
return redirect('signup')
form.save()
This method looks a bit unprofessional. Isn't there a built-in way like there always is in Django? Something like an argument in the username model
field.