Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
187 views
in Technique[技术] by (71.8m points)

python - no download dialog window using flask send_from_directory

Im using flask send_from_directory to test returning a file in a download dialog window

with this route which should return a file

@app.route('/client_choice', methods=['POST'])
def client_choice():

uploads = os.path.join(current_app.instance_path, current_app.config['UPLOAD_PATH'])
    main_file = str(main_file)
    return send_from_directory(directory=uploads, filename=main_file, as_attachment=True)

but does not return the file in a download dialog window the absolute path is correct also the filename

the route is called via a ajax post request

I tried the same with a test route which gets called via this link <a href="{{ url_for('service.test') }}">test</a>

separate route

@app.route('/test', methods=['GET'])
def test():
    uploads = os.path.join(current_app.instance_path, current_app.config['UPLOAD_PATH'])
    main_file = "same_file.xlsx"
    return send_from_directory(directory=uploads, filename=main_file, as_attachment=True)

with this route the file gets correctly downloaded

why does the first route does not return the file in a download window like the second route even if the code is totally the same expect the different request type which should be relevant

question from:https://stackoverflow.com/questions/65642170/no-download-dialog-window-using-flask-send-from-directory

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...