Flask Download a File

前端 未结 3 2011
梦毁少年i
梦毁少年i 2020-12-01 02:28

I\'m trying to create a web app with Flask that lets a user upload a file and serve them to another user. Right now, I can upload the file to the upload_folder corr

3条回答
  •  长情又很酷
    2020-12-01 03:06

    I was also developing a similar application. I was also getting not found error even though the file was there. This solve my problem. I mention my download folder in 'static_folder':

    app = Flask(__name__,static_folder='pdf')
    

    My code for the download is as follows:

    @app.route('/pdf/', methods=['GET', 'POST'])
    def download(filename):    
        return send_from_directory(directory='pdf', filename=filename)
    

    This is how I am calling my file from html.

    Download pdf 
    Download png 
    

提交回复
热议问题