Django电子邮件通知

时间:2015-05-12 10:54:07

标签: python django email-notifications

我想询问有关如何执行此Django电子邮件通知的指导 https://docs.djangoproject.com/en/1.8/topics/email/#send-mail

我有一个基本的任务表单和选项,可以在保存表单时将其分配给某人。我想向指定的用户发送电子邮件通知。

Job / task models.py

A.someMethod()

作业/任务view.py

class Job(models.Model):
    completed = models.BooleanField(default=False)
    task_name = models.CharField(max_length=80, blank=False)
    description = models.CharField(max_length=80, blank=False)
    is_important = models.BooleanField(default=False)
    completion_date = models.DateField(blank=True, null=True)
    assign_to = models.ForeignKey(User, blank=True, null=True)
    comments = models.TextField(blank=True)

    def __unicode__(self):
        return self.task_name

1 个答案:

答案 0 :(得分:0)

你快到了:

@login_required
def job(request):

    form = JobForm(request.POST or None)

    if form.is_valid():
        job_record = form.save(commit=False)
        job_record.assign_to = request.user
        job_record.save()
        send_mail(
            subject="subject",
            message="message",
            from_email="from@myserver.com",
            recipient_list=[job_record.assign_to.email]
        )
        return redirect('jobs:list')

    return render(request, 'jobs/form.html', {'form': form})