How do Django Forms validate data? Explain the role of clean(), clean_<field>(), and is_valid().
Last updated
is_valid()runs the full pipeline (full_clean()) and returnsTrueonly if no errors occurred. Errors go toform.errorsand validated values toform.cleaned_data.Order: each field first converts input (
to_python) and runs built-in validators. Thenclean_<field>()adds custom single-field checks, raisingValidationErrorand returning the cleaned value.clean()runs last for cross-field validation (e.g. password confirmation). Its errors are non-field errors by default, and it returns the fullcleaned_data.