【发布时间】:2017-08-10 09:58:54
【问题描述】:
在我的 django 视图中,我需要在子进程完成后发送电子邮件通知,因为子进程启动的脚本正在后台运行一些命令,所以在脚本完成之前发送电子邮件,有没有人知道我怎么能这样做?
我的看法:
def getor(request):
# process
subprocess.call("./step1.sh", shell=True)
#send notification
current_site = get_current_site(request)
user = User.objects.values('username').order_by('id').last()
us = user['username']
subject = 'Notification of endprocess.'
message = render_to_string('notify.html', {
'us':us,
'domain':current_site.domain,
})
eml = User.objects.values('email').order_by('id').last()
toemail = eml['email']
email = EmailMessage(subject, message, to=[toemail])
email.send()
return render(request, 'endexecut.html')
【问题讨论】:
-
我在 comunicate() 函数中遇到了一些错误,我所做的是在答案的评论中,无论如何,谢谢。
标签: python django subprocess