我希望登录用户能够发送他们创建的已保存在数据库中的模型对象的副本。我使用get(pk = id)来识别用户想要发送的特定的一个。问题是,send_mail()无法识别收件人电子邮件(至)。
@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()并且工作正常。感谢
答案 0 :(得分:1)
因为您已将to
设置为字符串"email"
。我怀疑这是你想做的事。
为什么不直接将email
变量传递给send_mail
来电?