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 trial

Python Django Forms Forms Validate a Form in a View

Jesper Sørensen
Jesper Sørensen
540 Points

Hi, I am getting two kinds of errors here. 1) I am not returning the right HttpResponseRedirect 2) the send_lead(...

I think it is call of the send_lead function that is wrong. I am passing in the two arguments that send_lead takes, and I am passing it in as cleaned data.

Any suggestions is appreciated

from django.core.mail import send_mail
from django.core.urlresolvers import reverse
from django.http import HttpResponseRedirect
from django.shortcuts import render

from . import forms

def send_lead(email, url):
        'Lead from {}'.format(email),
        '{} submitted {}'.format(email, url),

def lead_form(request):
    form = forms.LeadShareForm()
    if request.method == 'POST':
        form = forms.LeadShareForm(request.POST)
        if form.is_valid():
            send_lead(form.cleaned_data(['email']), form.cleaned_data(['link'])
            return HttpResponseRedirect(reverse('lead'))
    return render(request, 'lead_form.html', {'form': form})

1 Answer

Alex Koumparos
Alex Koumparos
Python Development Techdegree Student 36,887 Points

Hi Jesper,

Your problem is a typo: incorrect parentheses on this line:

send_lead(form.cleaned_data(['email']), form.cleaned_data(['link'])

It's clearer to see if we split the line up like this:


You're treating form.cleaned_data as though it is a function call instead of a dictionary. We can access the elements of form.cleaned_data like this: form.cleaned_data['email'].

When you correct your dictionary indexes, note also that you currently have mismatched parens, so for "link" you'll need to delete the opening paren but not the closing paren.

Hope that clears everything up for you.