我有这个功能。我想执行以下两行:
list = utils.get_connection().get_list_by_id(MAILCHIMP_LIST_ID)
list.subscribe(email_address, {'EMAIL': email_address, 'FNAME': fname, 'LNAME': lname})
如果他们失败了,我想将他们重定向到'/mailing_list_failure'
这是完整的功能:
def add_email_to_mailing_list(request):
if request.POST['email'] and len(request.POST['email']) > 4:
email_address = request.POST['email']
fname = request.POST['fname']
lname = request.POST['lname']
#If two next lines are failure return to '/mailing_list_failure/'
list = utils.get_connection().get_list_by_id(MAILCHIMP_LIST_ID)
list.subscribe(email_address, {'EMAIL': email_address, 'FNAME': fname, 'LNAME': lname})
return HttpResponseRedirect('/mailing_list_success/')
else:
return HttpResponseRedirect('/mailing_list_failure/')