Zru*_*ufy 3 javascript python flask
我的代码需要一些帮助。在我的网站中,我无法弄清楚如何解决问题。我通过 JavaScript 解释代码创建一个链接,让您下载静态文件夹请求的文档。这样做。
@ App.route ( '/ static / document / <path: name>', methods = [ 'POST'])
def downloads (name): #name is the name of the document
    return os.remove (name)
然后文件我拿了,但是文件没有删除。这是用于下载此文件的 javascript 代码。
downloadlink var = document.createElement ( "a");
                        d = obj.d; # D is download method before
                        downloadlink.href = d;
                        downloadlink.className = "DOWNLOAD_LINK";
                        downloadlink.download = n;
                        downloadlink.onClick = setTimeout (function () {location.reload (true);}, 30000);
                        downloadlink.innerHTML = "<p> Download document" + n + "</ p>";
                        document.getElementById ( "results"). appendChild (downloadlink);
我错在哪里?
用此代码解决。
@app.route('/path/<name>') 
def download(name): 
   file_path ="/path/"+name
   file_handle = open(file_path, 'r')
   @after_this_request 
   def remove_file(response): 
      os.remove("/path/"+name) 
      return response 
   return send_file(file_handle)
| 归档时间: | 
 | 
| 查看次数: | 3943 次 | 
| 最近记录: |