我想向在我的 django 应用程序中填写电子邮件字段的用户发送邮件。过程是这样的,当用户填写表单时,如果有效,它将保存在数据库中,并从数据库中选择用户电子邮件地址并发送邮件。我尝试了以下代码,但出现此错误:
ValueError at /confirm/
need more than 1 value to unpack
Request Method: POST
Request URL: http://127.0.0.1:8000/confirm/
Django Version: 1.4
Exception Type: ValueError
Exception Value:
need more than 1 value to unpack
Exception Location: C:\Python27\lib\site-packages\django\core\mail\message.py in sanitize_address, line 102
Python Executable: C:\Python27\python.exe
Python Version: 2.7.3
楷模
class Invite(models.Model):
email_address=models.EmailField(max_length=75)
def __unicode__(self):
return self.email_address
意见
def invite_me(request):
if request.method=="POST":
form=InviteForm(request.POST)
if form.is_valid():
form.save()
#get input data and send email to the user.
send_mail('Your Key Invite','Welcome to my world','test@gmail.com',
[Invite.objects.values('email_address')])
return HttpResponse('Thanks For Inputting Your Email, Go Check Your Email For Our Invite!')
else:
return HttpResponse('Invalid Email Address')
else:
form=InviteForm()
return render_to_response('home.html',{'InviteForm':InviteForm},context_instance=RequestContext(request))