Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
# coding: utf-8
import csv
from io import StringIO
from bottle import route, response, run
def download():
stream = StringIO()
writer = csv.writer(stream)
writer.writerow(["str", "string"])
writer.writerow(["int", 123])
# コンテンツタイプにapplication/octet-streamを指定
response.content_type = "application/octet-stream"
# ダウンロードするファイル名を指定
response.headers["Content-Disposition"] = "attachment; filename='test.csv'"
return stream.getvalue().encode("shift-jis")
if __name__ == "__main__":
run(host="localhost", port=8080)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment