It seems everything is correct, but nothing is downloaded.

Here is my method

@admin.route('/download_doc', methods=['GET', 'POST']) def download_doc(): doc_id = request.json['id'] doc = Doc.query.filter(Doc.id==doc_id).first() filename = doc.filename uploads = os.path.join(app.root_path, app.config['UPLOAD_FOLDER']) return send_from_directory(directory=uploads, filename=filename) 

But for some reason error 404 enter image description here

It is embarrassing that when I write for print for uploads, the following path is displayed. enter image description here

  • These tricks with slashes - funny WIndows. You probably have a slash such '/' everywhere in the application, and the Windows everywhere use this '\'. I do not know which one is direct. and what is the reverse. Comrade had something similar on Windows. - Narnik Gamarnik

1 answer 1

Try using os.path.normpath (). This function normalizes the path according to the operating system.

 >>> path_a = "D:\Desktop\test" >>> path_b = 'static/doc' >>> uploads = os.path.join(path_a, path_b) 'D:\\Desktop\test\\static/doc' >>> norm_uploads = os.path.normpath(uploads) 'D:\\Desktop\test\\static\\doc' 

It is also possible that the admin \ download_doc address does not really exist. If admin is a blueprint, check whether you specified a prefix for it during registration:

 app.register_blueprint(admin , url_prefix='/admin ')