Created
December 18, 2018 07:03
-
-
Save CVertex/d29e98fc1a5d4282c8248ddfc2f5d425 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import csv | |
import io | |
class CsvDownloadHandler(handlers.BaseAjaxHandler): | |
# TODO, POST instead of GET to avoid XSSI prefixes | |
def get(self): | |
self.response.headers['Content-Type'] = 'application/csv' | |
self.response.headers["Content-Disposition"] = 'attachment; filename="%s"' % 'all-sessions.csv' | |
# Build a string buffer | |
output = io.BytesIO() | |
# Write the CSV into the string buffer | |
writer = csv.writer(output) | |
writer.writerow(['foo','foo,bar', 'bar']) | |
writer.writerow(['foo','foo,bar', 'bar']) | |
writer.writerow(['foo','foo,bar', 'bar']) | |
# Write to the output stream | |
self._RawWrite(output.getvalue()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment