Skip to content

Instantly share code, notes, and snippets.

@josefmonje
Created March 29, 2016 07:28
Show Gist options
  • Save josefmonje/8dab348d563678155f65 to your computer and use it in GitHub Desktop.
Save josefmonje/8dab348d563678155f65 to your computer and use it in GitHub Desktop.
Django UserCreationForm - check if user exists
def clean_username(self):
username = self.cleaned_data["username"]
try:
User.objects.get(username=username)
except User.DoesNotExist:
return username
raise forms.ValidationError(_("A user with that username already exists."))
@Dominique-Remy
Copy link

Thanks !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment