开发者

how to create a downloadable csv file in appengine

开发者 https://www.devze.com 2023-03-21 14:30 出处:网络
I use python Appengine. I\'m trying to create a link on a webpage, which a user can click to download a csv file. How can I do this?

I use python Appengine. I'm trying to create a link on a webpage, which a user can click to download a csv file. How can I do this?

I've looked at csv module, but it seems to want to open a file on the server, but appengine doesn't allow that.

I've looked at remote_api, but it seems that its only for uploading or downloading using app confi开发者_开发百科g, and from account owner's terminal.

Any help thanks.


Pass a StringIO object as the first parameter to csv.writer; then set the content-type and content-disposition on the response appropriately (probably "text/csv" and "attachment", respectively) and send the StringIO as the content.


I used this code:

self.response.headers['Content-Type'] = 'application/csv'
writer = csv.writer(self.response.out)
writer.writerow(['foo','foo,bar', 'bar'])

Put it in your handler's get method. When user requests it, user's browser will download the list content automatically.

Got from: generating a CSV file online on Google App Engine

0

精彩评论

暂无评论...
验证码 换一张
取 消