户上传一个文件,通过后台处理后再返回给用户,并根据结果更新当前页面,这要怎么实现?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
提交
取消