[英]Server-side python returning a zip file for a download
Using my client I pass a parameter by get to a python script on the server, it runs a process and creates a zip file.使用我的客户端,我通过 get 到服务器上的 python 脚本传递一个参数,它运行一个进程并创建一个 zip 文件。 In my client side JavaScript my ajax call just tells me it was able to pass the data to my python script.
在我的客户端 JavaScript 中,我的 ajax 调用只是告诉我它能够将数据传递给我的 python 脚本。
I've tried sys.stdout.write(b"zipfilename")
but nothing happens.我试过
sys.stdout.write(b"zipfilename")
但没有任何反应。 If I can't pass the file back, is there a way to pass something back so my JavaScript knows it's done?如果我无法将文件传回,有没有办法传回一些东西,以便我的 JavaScript 知道它已完成? I'm not using NODE or Angular.
我没有使用 NODE 或 Angular。 My python script does run and creates the zip file on the server but the JavaScript page doesn't know it nor does a download dialog appear.
我的 python 脚本确实运行并在服务器上创建了 zip 文件,但 JavaScript 页面不知道它,也没有出现下载对话框。 I'm missing something basic but I can't find it.
我缺少一些基本的东西,但我找不到它。
My JS AJAX call:我的 JS AJAX 调用:
$.ajax({ url: theUrl, type: 'get', success: function(response){ } });
The end of my python script:我的python脚本结束:
def createZip(v, charset=None):
with ZipFile(v +'.zip', 'w') as myzip:
myzip.write(v +'.shp')
myzip.write(v +'.shx')
myzip.write(v +'.dbf')
myzip.write(v +'.prj')
return 'c:/dev/python/'+ v + '.zip'
createZip(fn)
It's hard to tell based on the limited code provided, but here's some general points:根据提供的有限代码很难判断,但这里有一些一般要点:
sys.stdout.write
is going to write to the output of the application running the Python script, not to a HTTP response (unless it's running as a WSGI application). sys.stdout.write
将写入运行 Python 脚本的应用程序的输出,而不是写入 HTTP 响应(除非它作为 WSGI 应用程序运行)。download
attribute is set on the anchor which links to the file).download
属性)时,才会出现下载提示。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.