1👍
You need to call .is_valid()
on form before accessing cleaned_data
attribute.
There is not calling form.is_valid()
in your views.py.
Also there is no populating of your form from POST data, you need to do it with form = LoginForm(request.POST)
if your request.method
is POST
You can also view the source:
full_clean()
is respected for assigning self.cleaned_data
, and full_clean()
is called by property self.errors
in is_valid()
method. So you can track from the django source code what is wrong with yours.
0👍
You haven’t called form.is_valid()
.
Inorder to access form.cleaned_data, the form validation should be done first.
Form validation is carried out only when form.is_valid()
is called upon the form, which in turn returns a validated cleaned_data
.
Also, on request.POST
, your form is not getting data, because, for that, you need to initialise your form with request.POST
, like
form = LoginForm(request.POST)
The return statement before the last render_to_response
would also raise some errors, I presume.
You could read more about form validation here from the docs