在django admin中验证用户的应用程序正确后,我需要向用户发送自定义电子邮件。电子邮件将发送给单个用户。所以我必须从视图到表单传递当前用户的ID,因为渲染模板是通过表单按钮小部件
collect
forms.py
views.py
def emails(request):
subject = 'leave confirmation'
message = ' your leav application approved'
email_from = settings.EMAIL_HOST_USER
x=leavdb11.objects.all()
for i in x:
if i.id:
recipient_list=[i.email]
send_mail( subject, message, email_from,recipient_list)
return HttpResponse("send")
此代码将为所有注册用户发送电子邮件。我想为当前所选用户发送电子邮件