实现文件的下载

report = CustomHistoryReport.objects.filter(id=reportid)
	if report:
		abs_path = REPORT_PATH + report[0].name + '.xlsx'
		if not os.path.isfile(abs_path):  # 判断下载文件是否存在
			return Response(status=404)
		else:
			with open(abs_path, 'rb') as report:
				file_content = report.read()
			res = file_content
			response = HttpResponse()
                       #声明流数据的类型
			response['Content-Type'] = 'application/octet-stream'
                        #将流数据写入到相应对象中
			response.write(res)
			return response
原文地址:https://www.cnblogs.com/cizao/p/11481877.html