我试图让用户在访问 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 的初学者。
希望你能帮助我。