Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialrobertdumas2
481 PointsCleaning Honeypot Field?
I'm trying to clean the honeypot field, but it fails when I check my work. What am I missing here?
from django import forms
class LeadShareForm(forms.Form):
email = forms.EmailField()
link = forms.URLField()
honeypot = forms.CharField(required=False,widget=forms.HiddenInput)
def clean_honeypot(self):
honeypot = self.cleaned_data['honeypot']
if len(honeypot):
raise forms.ValidationError('Error: Honeypot should be left empty.')
return honeypot
1 Answer
Chris Freeman
Treehouse Moderator 68,427 PointsYou code is close. There is an indention issue and the return should be in an else
block:
class LeadShareForm(forms.Form):
email = forms.EmailField()
link = forms.URLField()
honeypot = forms.CharField(required=False,widget=forms.HiddenInput)
def clean_honeypot(self):
honeypot = self.cleaned_data['honeypot']
if len(honeypot):
raise forms.ValidationError('Error: Honeypot should be left empty.')
else:
return honeypot
Deep Sukhwani
Courses Plus Student 2,359 PointsDeep Sukhwani
Courses Plus Student 2,359 PointsWhy does it "HAVE" to be in else block?
Chris Freeman
Treehouse Moderator 68,427 PointsChris Freeman
Treehouse Moderator 68,427 PointsDeep Sukhwani, you are correct that the
return
does not have to be in anelse
block.