Skip to content
Justice Tech School

Custom Validation

clean_<field> checks one field.

Example
class SignUp(forms.Form):
    username = forms.CharField()

    def clean_username(self):
        u = self.cleaned_data["username"]
        if " " in u:
            raise forms.ValidationError("No spaces")
        return u

Exercise

Raise an error.

raise forms.Error("x")

Quiz Test

What must clean_x return?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.