文件下载后刷新页面

pjngdqdw  于 2021-08-25  发布在  Java
关注(0)|答案(0)|浏览(278)

此代码将获取一个pdf文件并返回一个.txt文件作为下载:

from flask import Flask, make_response, request, render_template
from werkzeug.utils import secure_filename
import os

from processing import get_numbers

app = Flask(__name__)

@app.route("/", methods=["GET", "POST"])
def my_page():
    if request.method == "POST":
        f = request.files.get("file")
        if f:
            filename = secure_filename(f.filename)
            file_path = os.path.join('temp_files', filename)
            f.save(file_path)
            output_data = get_numbers(file_path)
            response = make_response(output_data)
            response.headers["Content-Disposition"] = \
                f"attachment; filename={filename[:-4]}.txt"
            os.remove(file_path)

            return response

    return render_template('index.html')

if __name__ == "__main__":
    app.run(debug=True)

下载文件后(返回响应后),如何重新加载页面?

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题