当用户访问pge时,我试图让用户下载pptx文件,比如说:http://127.0.0.1:8080/download
下面是我的代码片段:
from pptx import Presentation
from cherrypy.lib.static import serve_file
@cherrypy.expose
def download(self):
prs = Presentation()
title_slide_layout = prs.slide_layouts[0]
slide = prs.slides.add_slide(title_slide_layout)
title = slide.shapes.title
subtitle = slide.placeholders[1]
title.text = "Hello, World!"
subtitle.text = "python-pptx was here!"
pptx = prs.save('test.pptx')
return serve_file(path, "application/x-download", "attachment")我真的不明白serve_file是如何工作的,我也不知道这样做是否正确。我是CherryPy的初学者。
希望你能帮我一把。
发布于 2017-05-27 09:51:01
只是一次更新。我用过static.serve_file,它起作用了!
return static.serve_file(path, "application/x-download",
"attachment", name =os.path.basename(path))https://stackoverflow.com/questions/42810474
复制相似问题