Here is a complete example of using the Python CSV module in GAE. I usually use it to create a csv file from a gql request and ask the user to save or open it.
import csv class MyDownloadHandler(webapp2.RequestHandler): def get(self): q = ModelName.gql("WHERE foo = 'bar' ORDER BY date ASC") reqs = q.fetch(1000) self.response.headers['Content-Type'] = 'text/csv' self.response.headers['Content-Disposition'] = 'attachment; filename=studenttransreqs.csv' writer = csv.writer(self.response.out)
create line shortcuts
writer.writerow(['Date', 'Time','User' ])
repeat query returning each instance as a string
for req in reqs: writer.writerow([req.date,req.time,req.user])
Add the appropriate mapping so that clicking on the link opens a file dialog box
('/mydownloadhandler',MyDownloadHandler),
source share