相关疑难解决方法(0)

使用Flask生成word文档?

我正在尝试启动单页烧瓶应用程序,允许用户下载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')
Run Code Online (Sandbox Code Playgroud)

python flask python-docx

2
推荐指数
1
解决办法
2501
查看次数

Flask 显示 TypeError: send_from_directory() 缺少 1 个必需的位置参数:'path'

当我在 Azure 上部署 Flask 应用程序时,视图会引发TypeError: send_from_directory() missing 1 required positional argument: 'path'. 当我在本地运行时,这不会发生。

from flask import send_from_directory

@app.route('/download/<path:filename>', methods=['GET', 'POST'])
def download(filename):
    uploads = os.path.join(app.root_path, app.config['UPLOAD_FOLDER'])
    return send_from_directory(directory=uploads, filename=filename)
Run Code Online (Sandbox Code Playgroud)

python flask

0
推荐指数
1
解决办法
1878
查看次数

标签 统计

flask ×2

python ×2

python-docx ×1