在django发送每个请求的邮件 [英] Send mail per request in django
问题描述
当用户从我的django网络应用程序下载文件时,我想通过发送邮件通知上传者他的文件已被下载。问题是,如果我下载一个 我只是希望每次下载向上传者发送一封邮件通知。 视图: download.txt 如何根据下载请求发送邮件? 我会建议不同的方法... 当有人下载文件时,事件到您的数据库上的表。 稍后(作为crontab批处理或保存监听器)发送电子邮件。 This is really killing me. I've been dealing with this for days. When a user download a file from my django web app, I want to notify the uploader that his file has been downloaded by sending a mail. The problem is, If I should download a I just want it to send one mail notification to the uploader per download. views: download.txt How can I send mail per download request? I would suggest a different approach... When someone download the file, log the event to a table on your database. Later on (as a crontab batch, or save listener) send the emails. 这篇关于在django发送每个请求的邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!低文件大小(489kb)
,它将向上传者发送一条邮件
。但是如果我下载一个3MB或以上的文件大小
,它将向上传者发送 c $ c>多个邮件 / p>
@login_required
def document_view请求,emov_id):
fileload = Emov.objects.get(id = emov_id)
filename = fileload.mov_file.name.split('/')[ - 1]
filesize = fileload .mov_file.size
response = HttpResponse(fileload.mov_file,content_type ='')
response ['Content-Disposition'] ='attachment; filename =%s'%filename
response ['Content-Length'] = filesize
send_mail('你的文件刚刚被下载',loader.get_template('download.txt')。render ({'fileload':fileload})),'test@example.com',[fileload.email,])
返回响应
'您的文件{{fileload.name}}已被下载!
写入会话ID,文件名,用户名。
确保session_id + file_name + user_name 唯一键
这样,您可以获得更多可以帮助您的信息。
您甚至可以发送每日/每周报告等... low file size (489kb)
, it will send a mail once to the uploader
. But if I should download a file size of 3mb or above
it will send more than one mail to the uploader
.@login_required
def document_view(request,emov_id):
fileload = Emov.objects.get(id=emov_id)
filename = fileload.mov_file.name.split('/')[-1]
filesize=fileload.mov_file.size
response = HttpResponse(fileload.mov_file, content_type='')
response['Content-Disposition'] = 'attachment; filename=%s' % filename
response['Content-Length'] = filesize
send_mail('Your file has just been downloaded',loader.get_template('download.txt').render(Context({'fileload':fileload})),'test@example.com',[fileload.email,])
return response
'Your file {{ fileload.name}} have been downloaded!'
Write the Session ID, the file name, the user name.
Make sure that session_id+file_name+user_name are unique key
This way, you can get much more information that can help you later.
You can even send a daily/weekly report and so on...