def validate_signup(request): ''' Validates signup POSTed via AJAX - disallows any other input ''' if request.is_ajax() and request.method == "POST": email = request.POST['email'] subscribe(email) message = "<p>Thanks for signing up!</p>" return HttpResponse(message) else: raise Http404
def home(request): ''' Display home.html with mailing list subscribe form ''' if request.method == 'POST': form = SubscribeForm(request.POST) if form.is_valid(): # Gather what's needed email = form.cleaned_data['email'] subscribe(email) return HttpResponseRedirect('/thanks/') else: form = SubscribeForm() return render_to_response('home.html', { 'form': form, }, context_instance=RequestContext(request) )