Complete the code to define a custom clean method for the 'email' field in a Django form.
def clean_[1](self): email = self.cleaned_data.get('email') if not email.endswith('@example.com'): raise forms.ValidationError('Email must be from example.com domain') return email
The method name must be clean_email to validate the 'email' field specifically.
Complete the code to raise a validation error if the 'age' field is less than 18.
def clean_age(self): age = self.cleaned_data.get('age') if age [1] 18: raise forms.ValidationError('You must be at least 18 years old') return age
The condition should check if age is less than 18 using '<'.
Fix the error in the custom form validation method to correctly check if the username contains spaces.
def clean_username(self): username = self.cleaned_data.get('username') if ' ' [1] username: raise forms.ValidationError('Username cannot contain spaces') return username
To check if a space is inside the username string, use the 'in' keyword.
Fill both blanks to create a custom form validation method that checks if the password and confirm_password fields match.
def clean(self): cleaned_data = super().[1]() password = cleaned_data.get('password') confirm = cleaned_data.get('[2]') if password != confirm: raise forms.ValidationError('Passwords do not match') return cleaned_data
The method calls super().clean() to get cleaned data, and the confirm password field is named 'confirm_password'.
Fill all three blanks to create a custom validation method that ensures the 'title' field is capitalized and at least 5 characters long.
def clean_[1](self): title = self.cleaned_data.get('[2]') if len(title) [3] 5: raise forms.ValidationError('Title must be at least 5 characters long') return title.capitalize()
The method name is 'clean_title', it gets the 'title' field, and checks if length is less than 5.