Google News
logo
Django - Interview Questions
What are custom validation rules in form data?
Custom validation rules are the customized rules used for form validation. Suppose we have a feedback form. There are fields like messages, email, and subject. If we get message data of 1 or 2 words that are of no use to us. To check the issue, we use custom validation rules.
 
We simply define a method in our forms.py by the name clean_message().
 
This is the Django way to do it. The method’s name for custom validation should start with a clean_fieldname(). Django form system automatically looks for this type of method. Thus, these are called custom validation rules in Django.
 
It is always important to return the cleaned data of the field in a custom validation method. If not done, the method will return none instead resulting in loss of data.
Advertisement