Validation checks whether submitted or stored values meet expected correctness or format rules. In Django, field configuration can add these checks on top of the database representation: an EmailField, for example, stores text while checking that input resembles an email address. section 4.8
For web forms, validation sits between submission and the next response. A browser first uses GET to retrieve the form, then sends the entered values with POST. The view binds request.POST to a form and calls is_valid(). Valid data can be processed and followed by a redirect; invalid data keeps the user on the form page with error information. section 7.1.1
A practical validation flow looks like this:
- Create an unbound form for a GET request so the user sees empty fields. section 7.1.1
- Bind submitted values with CommentForm(request.POST) when the request is a POST. section 7.1.1
- Call form.is_valid(); when it succeeds, read validated values through cleaned_data. section 7.1.1
- Process valid input and redirect to a confirmation page; otherwise render the form again with its errors. section 7.1.1
Comment submission
A comment view uses one URL for both display and submission. GET creates CommentForm(), while POST creates CommentForm(request.POST). If is_valid() returns true, the view obtains name and comment from cleaned_data, sends the message, and redirects to comment_accepted. If validation fails, the same form-rendering path displays the errors. section 7.1.1
Figure 7.2 Logic flow for a view that handles form submission
Follow the request-flow diagram to see how GET, POST, successful validation, redirects, and invalid-form redisplay fit together. section 7.1.1





























