【发布时间】:2021-03-15 20:34:11
【问题描述】:
我有一个类似的功能:
def download(requests):
with open(file_path2, 'rb') as fh:
response = HttpResponse(fh.read(), content_type="application/vnd.ms-excel")
response['Content-Disposition'] = 'inline; filename=' + os.path.basename(file_path2)
return response #it stop executing here as we return.
os.remove(file_path2)
return render(request, 'user/charts.html', {'res': 'The file has decrypted'})
所以该函数需要做的是,开始下载文件,下载后从系统中删除文件,然后重定向到其他页面。
但问题是,为了实现下载功能,我使用return然后它停止了,那么我该如何执行下一条语句?
【问题讨论】:
标签: python-3.x django file download