When building custom django auth login form using Phone number and Email, I got this errors:
1 2 | KeyError at /login/ u’no_cookies’ |
And it’s failed on this steps:
1 | self.check_for_test_cookie() |
Let see the part of code:
1 2 3 4 5 6 7 8 9 | def clean(self): cleaned_data = super(CustomAuthForm, self).clean() username = cleaned_data.get(‘username’) password = cleaned_data.get(‘password’) if username and password: self.user_cache = authenticate(username=username, password=password) …. |
After compare with https://github.com/django/django/blob/master/django/contrib/auth/forms.py, I found the problem :
1 | cleaned_data = super(CustomAuthForm, self).clean() |
Yes, this is the mistake.
To solve this, just get username and password from self.cleaned_data.
1 2 3 | def clean(self): username = self.cleaned_data.get(‘username’) password = self.cleaned_data.get(‘password’) |