Form and field validation
Form and field validation
Form validation happens when the data is cleaned. If you want to customize this process, there are various places to make changes, each one serving a different purpose. Three types of cleaning methods are run during form processing. These are normally executed when you call the is_valid()
method on a form. There are other things that can also trigger cleaning and validation (accessing the errors
attribute or calling full_clean()
directly), but normally they won’t be needed.
In general, any cleaning method can raise ValidationError
if there is a problem with the data it is processing, passing the relevant information to the ValidationError
constructor. See below for the best practice in raising ValidationError
. If no Valid