【发布时间】:2020-04-06 10:19:30
【问题描述】:
我正在使用 Python hug API 想为前端创建一个 GET API。前端可以下载创建的 Word 文档文件,例如通过下载按钮。但是,经过documentation 之后,我仍然想不出办法。
到目前为止,这是我的工作脚本:
import os
import hug
from docx import Document
@hug.get("/download_submission_document")
def download_submission_document():
file_name = 'example.docx'
document = Document()
document.add_heading('Test header', level=2)
document.add_paragraph('Test paragraph')
document.save(file_name)
# TO DO: send a created file to frontend
我不确定我们是否可以立即发送对象,或者我们必须先将其保存在某个地方,然后再发送前端。 (要求:hug、python-docx)
我正在尝试使用类似的东西
@hug.get("/download_submission_document", output=hug.output_format.file)
但不确定如何返回文件。
【问题讨论】:
标签: python python-3.x hug