Every field in Form has validators which check the value against their 
conditions.
as Django Doc sais 
<https://docs.djangoproject.com/en/2.1/ref/forms/api/#django.forms.Form.is_valid>
:
The primary task of a Form 
<https://docs.djangoproject.com/en/2.1/ref/forms/api/#django.forms.Form> 
object is to validate data. With a bound Form 
<https://docs.djangoproject.com/en/2.1/ref/forms/api/#django.forms.Form> 
instance, call the is_valid() 
<https://docs.djangoproject.com/en/2.1/ref/forms/api/#django.forms.Form.is_valid>
 
method to run validation and return a boolean designating whether the data 
was valid

Take a look at is_valid at Django source code 
<https://github.com/django/django/blob/cbf7e71558c94ce1c327b683768a18a25d82d197/django/forms/forms.py#L178>
 
(At BaseForm's source code).
as you see there it checks if the form is bound and *not has errors.*

If you see *errors*, it's a method with attribute decorator. that triggers 
the full_clean( ) method.
full_clean does _clean_fields which populates the *cleaned_data *with 
validation checked data.

So, If you call the is_valid() and it returns True, You know that all form 
validators are applied to the data and it had no errors. also the 
cleaned_data is ready to use.

On Friday, March 22, 2019 at 10:43:03 PM UTC+4:30, omar ahmed wrote:
>
> hello guys
> i created contact form
> in my view :
> if form.is_valid():
> message = form.cleaned_data['message']
> what is .is_valid() method and what is cleaned_data attribute ???
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/d6ec41ed-b01d-42b8-bc57-9026988248e2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to