Learn HTML
Learn CSS
Learn Javascript
Django Introduction
Django Project & File Structure
Django Create & Structure Directory of Application
Django View
Django Template
Django Dynamic Templates Using DLT
Django if,elif,else & for loop tags
Django Static Files
Django Template & Static File Inheritance
Django Hyperlinks
django Get Post Csrf
Django Administration
Django Model class
Django Form
Django Get Form Data & Data Validation
Django Redirect Page After Submit
Django Save,Update & Delete Form in database
Django Dynamic URL
Django User Authentication System
After filling the fields by the value we have to validate those data. Suppose user put an email. In this case
validate means, is the user write the correct format of the mail, does the user use "@" symbol or not, etc.
After doing the validation you have to put the data in the database or do whatever you want.
In django we don't need to do code for validation because it is already done by django but we have to run that
validation.
is_valid():
This method is used to run the validation.If the data are valid then it will return True otherwise False.
cleaned_data:
This is an attribute and this is used to access the clean data. Clean data means, suppose the data given by
user is valid, so it is a clean data.Now to access those data this attribute will be used. cleaned_data only
contains valid fields in the form of dictionary. In the dictionary fields name become the dictionary key and
the inputted value by user become the value of the key. Suppose there is 5 fields. So in the dictionary there
will be 5 key value pair.
It means that at first user will fill the fields and the validation will be performed and if the data is valid then you can show those data in terminal.
Here if condition says that, if the method of request is POST then create the form object. If the form object
is valid then print the form is valid and print the other form. If this condition isn't true then in the else
part simply create the form object and render the form object.
Now there can be a question and that is:
How the method of request can be POST?
The answer is, you have to pass method attribute value POST in the form opening tag .
By using these two lines we are printing the value of which is putted by user in each field in the
terminal.
If don't want to print values in terminal then don't use these two lines of code.
To do this one method is used and that is clean_fieldName().
To do this one method is used and that is clean_fieldName().