1

我希望登录用户能够发送他们创建的已保存在数据库中的模型对象的副本。我正在使用 get(pk=id) 来识别用户想要发送的特定内容。问题是,send_mail() 无法识别收件人电子邮件 (to)。

   @login_required
    def email_query(request, id):
        history = Carloan_form.objects.get(pk=id)
        subject = 'Nigerian Loan Calculator Query e-mail'
        from_email = 'xxxx@gmail.com'
        email = request.user.email
        to = "email"
        send_mail(subject,get_template('carloan/loancalc-query.txt').render(Context({'history':history})),\
                 from_email,[to], fail_silently=False)
        return HttpResponse('sent')

更新

@login_required
def email_query(request, id):
    history = Carloan_form.objects.get(pk=id)
    subject = 'Nigerian Loan Calculator Query e-mail'
    from_email = 'ajibike.ca@gmail.com'
    email = request.user.email
    send_mail(subject,get_template('carloan/loancalc-query.txt').render(Context({'history':history})),\
             from_email,[email,], fail_silently=False)
    return HttpResponse('/history_query_sent/')

刚刚决定将电子邮件直接传递到 send_mail() 并且它起作用了。谢谢

4

1 回答 1

1

因为您已设置to为 string "email"。我怀疑那是你想要做的。

为什么不将email变量直接传递给send_mail调用?

于 2012-12-04T12:57:42.880 回答