我正在尝试启动一个允许用户下载 Word 文档的单页烧瓶应用程序。我已经想出了如何使用 python-docx 制作/保存文档,但现在我需要使文档在响应中可用。有任何想法吗?
这是我到目前为止所拥有的:
from flask import Flask, render_template
from docx import Document
from cStringIO import StringIO
@app.route('/')
def index():
document = Document()
document.add_heading("Sample Press Release", 0)
f = StringIO()
document.save(f)
length = f.tell()
f.seek(0)
return render_template('index.html')