python manage.py makemigrations api
python manage.py migrate
Login(ur="test",params="").save()
DocumentRoot "E:/demo/mysite"
Listen 192.168.1.100:8001
def download_excel(request):
def file_iterator(file_name, chunk_size=512):
with open(file_name, 'rb') as f:
while True:
c = f.read(chunk_size)
if c:
yield c
else:
break
file_path = request.POST["excel"]
file_name1 = os.path.join(settings.BASE_DIR, "api/Report", file_path + ".xlsx")
http_file = "http://192.168.1.100:8001/api/Report/" + file_path + ".xlsx"
response = HttpResponse(file_iterator(file_name1))
response['Content-Type'] = 'application/octet-stream'
response['Content-Disposition'] = 'attachment;filename="{0}"'.format("report.xlsx")
result = {'code': 0, 'msg': '下载成功', "path": http_file}
return JsonResponse(result)