After a Django form passes validation, cleaned_data gives the view a dictionary of field names and their validated, converted values. Treat it as the form’s reliable handoff to application logic: inspect it, build a message, save data, or trigger another action. section 7.1.1 section 7.6
A typical form-submission flow uses cleaned_data like this:
- Create a bound form with request.POST when the request uses POST. section 7.1.1
- Call form.is_valid(); only continue when it returns True. section 7.1.1 section 7.6
- Read values with field-name keys such as form.cleaned_data["name"]. section 7.1.1
- Use those values in the view’s next operation, then redirect or render a response. section 7.1.1
Reading a submitted comment
if form.is_valid(): name = form.cleaned_data["name"] comment = form.cleaned_data["comment"] message = f"Received comment from {name}\n\n{comment}" send_mail("Received comment", message, "admin@example.com", ["admin@example.com"], fail_silently=False) return redirect("comment_accepted") Here, validation comes first; cleaned_data supplies the name and comment for the email. Invalid submissions stay on the form-rendering path instead of reaching this block. section 7.1.1 section 7.6
Figure 7.2 Logic flow for a view that handles form submission
Use the request-flow diagram to follow the split between displaying a form, validating a POST, processing cleaned_data, and returning a response. section 7.1.1
