from django.http import HttpResponse
# use custom response class to override HttpResponse.close()
class HttpResponseAndMail(HttpResponse):
def __init__(self, article="", people=[], *args, **kwargs):
super(HttpResponseAndMail, self).__init__(*args, **kwargs)
self.article = article
self.people = people
def close(self):
super(HttpResponseAndMail, self).close()
# do whatever you want, this is the last codepoint in request handling
if self.status_code == 200:
send_mail(subject="", from_email="", message=self.article, recipient_list=self.people)
您可以通过创建自定义HttpResponse对象来完成此操作:
这段代码是在同一个python线程中运行的,但是只有在其他所有事情都完成之后才能运行,因此不会减慢web服务器的速度。在
相关问题 更多 >
编程相关推荐