Unable to retrieve files from send_from_directory() in flask

前端 未结 5 805
忘掉有多难
忘掉有多难 2020-12-09 16:47

I have a html file which references static object like this



         


        
5条回答
  •  伪装坚强ぢ
    2020-12-09 17:25

    You should remove "/" before "/static" in your code:

    send_from_directory('/static', filename)
    

    change it to:

    send_from_directory('static', filename)
    

    However, in some environments, the server itself does not let running this command on the static folder/directory. Because it is set to be a static file server. For example, with the google cloud, you should build a directory called tmp beside the static folder and then do the send_from_directory command with the tmp folder:

    return(send_from_directory('tmp', filename))
    

提交回复
热议问题