Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 14418

Generating word docs with Flask?

$
0
0

I'm trying to spin up a single page flask application that allows users to download a word document. I've already figured out how to make/save the document using python-docx, but now I need to make the document available in the response. Any ideas?

Here's what I have so far:

from flask import Flask, render_templatefrom docx import Documentfrom 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')

Viewing all articles
Browse latest Browse all 14418

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>