开发者

how to create a downloadable csv file in appengine

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜