如何使用flask在python脚本中处理上载的csv文件
如何通过为python脚本提供文件路径来处理上载的文件并下载处理后的文件?如何使用flask在python脚本中处理上载的csv文件,python,flask,pycharm,Python,Flask,Pycharm,如何通过为python脚本提供文件路径来处理上载的文件并下载处理后的文件? 代码 @app.route("/upload", methods=['POST']) def upload(): target = os.path.join(APP__ROOT, 'data/') print(target) if not os.path.isdir(target): os.mkdir(target) for file in request.files.ge
代码
@app.route("/upload", methods=['POST'])
def upload():
target = os.path.join(APP__ROOT, 'data/')
print(target)
if not os.path.isdir(target):
os.mkdir(target)
for file in request.files.getlist("file"):
filename = file.filename
print(filename)
destination = "/".join([target, filename])
print(destination)
file.save(destination)
return render_template("downloads.html")
您需要返回该文件
response = app.make_response(file)
response.headers["Content-Disposition"] = "attachment; filename=yourfile.csv"
return response
向何处发送此响应我有一个python脚本,该脚本采用路径,但不保存在何处,因为我在终端上运行它,现在我必须上传文件和进程,然后下载。嗨,你解决了这个问题吗?我也需要做这件事。