[英]Error When Using Django send_mail() Function
我想向在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))
考虑一下Invite.objects.values('email_address')
返回什么? 绝对不是send_mail
函数接受的内容(电子邮件地址列表)。
您需要Invite.objects.values_list('email_address', flat=True)
。 哦,删除[]
。
send_mail('foo', 'bar', 'baz@example.com', Invite.objects.values_list(...))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.