[Django]-KeyError at /login/

4👍

File "C:\o\17\mysite\pet\forms.py" in authenticate_via_email
62.                 email = self.cleaned_data['email']

You are accessing an element in the dictionary that does not exists. Try this:

email = self.cleaned_data.get('email', None)
if email:
    (...)
return None
👤Salem

1👍

def clean(self):
    cleaned_data = super(LoginForm, self).clean()
    if self._errors:
       return cleaned_data
    ...

Easily solve this kind of problems. If the field is required, you can expect that the key is there

Leave a comment