用戶上傳一個文件,通過后臺處理后再返回給用戶,并根據(jù)結(jié)果更新當(dāng)前頁面,這要怎么實現(xiàn)?django有辦法同時完成這兩個嗎?還是要借助前端完成?def table(request): if request.method == 'POST':
form = ExcelSubmit(request.POST, request.FILES) if form.is_valid():
excel = form.cleaned_data['excel']
filename = os.path.splitext(excel.name)[0] path = os.getcwd() + '/data/' + filename
table_generation(excel, path)
file_zip(path)
response = FileResponse(open(path + '.zip', 'rb'))
response['Content-Type'] = 'application/octet-stream'
response['Content-Disposition'] = 'attachment;filename=' + filename + '.zip'
return response else:
form = ExcelSubmit() return render(request, 'index.html', {'form': form, 'what': '表單提交'})
添加回答
舉報
0/150
提交
取消