Skip to content

Instantly share code, notes, and snippets.

@meganlkm
Created May 22, 2018 15:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save meganlkm/6e150f0074c193f3bbbd850c5e42bd03 to your computer and use it in GitHub Desktop.
Save meganlkm/6e150f0074c193f3bbbd850c5e42bd03 to your computer and use it in GitHub Desktop.
download a rendered template as a StringIO object in a Flask app
from StringIO import StringIO
from flask import Flask, render_template, send_file
app = Flask(__name__)
@app.route('/bootstrap')
def bootstrap():
str_io = StringIO()
str_io.write(render_template('files/bootstrap.sh.j2'))
str_io.seek(0)
return send_file(
str_io,
attachment_filename='bootstrap.sh',
as_attachment=True
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment