Lesson 16 — Form cleaning
Clean, then check
Django forms run a clean step for every field: remove extra spaces, fix the format, and raise an error if the value is unusable. Users type " sam " all the time.
" sam ".strip().title() # 'Sam'
strip() removes spaces at both ends; title() makes the first letter of each word capital.
Note: the exercise runs in your browser without Django installed, so it is a small plain-Python simulation of what Django does for you.
Why it matters: cleaned data means "Sam", " sam" and "SAM " are not stored as three different people.
Finish clean(): strip spaces, raise ValueError("name is required") if empty, and return the name in title case.
Run your code — when the output matches the task, you will see a green check. Then mark the lesson complete.
A quick 3-question quiz on this lesson — instant feedback.
Ready for more? Optional paid resources that pick up where this lesson leaves off.
Some links on this page are affiliate links: we may earn a commission at no extra cost to you. As an Amazon Associate I earn from qualifying purchases.
Project-based Django Foundations courses if you want a structured paid path after the free lessons. Wait for a sale — prices drop often.
Browse on Udemy →Search Amazon for Django Foundations books — check the publication year so the examples match current versions.
Search Amazon →