def clean_username(self):
    username = self.cleaned_data['username']
try:
    User.objects.get(username=username)
except User.DoesNotExist:
    raise forms.ValidationError('The username you have entered does not exist.'
        )
return username
Separately validating username and password during Django authentication