|
View:
New views
4 Messages
—
Rating Filter:
Alert me
|
|
|
how to return csv data?there is an easy way in controller methods to return json data,
@expose('json') when I put this expose decorator, it returns json data and this is a very nice feature of tg. is there anything similar like this for returning csv data? I need to return some csv data with header row at the top. Some of my users want to get data from the web application as excel files and I did not want to dive in to generate an excel file, giving them a csv file will solve both ms office and openoffice users problems. So, is there an example controller method to return csv data? -- You received this message because you are subscribed to the Google Groups "TurboGears" group. To post to this group, send email to turbogears@.... To unsubscribe from this group, send email to turbogears+unsubscribe@.... For more options, visit this group at http://groups.google.com/group/turbogears?hl=en. |
|
|
Re: how to return csv data?On Thursday, July 08, 2010 14:30:10 Timuçin Kızılay wrote:
> there is an easy way in controller methods to return json data, > @expose('json') > when I put this expose decorator, it returns json data and this is a > very nice feature of tg. > is there anything similar like this for returning csv data? I need to > return some csv data with header row at the top. Some of my users want > to get data from the web application as excel files and I did not want > to dive in to generate an excel file, giving them a csv file will solve > both ms office and openoffice users problems. > > So, is there an example controller method to return csv data? @expose(content_type="text/csv") def get_csv(self, **kwargs): """ Returns a *.csv """ filename = "test.csv" the_csv = "a,b,c\n1,2,3" # use module CSV to create this. response.headers["Content-Disposition"] = "attachment;filename=%s" % filename return the_csv Diez -- You received this message because you are subscribed to the Google Groups "TurboGears" group. To post to this group, send email to turbogears@.... To unsubscribe from this group, send email to turbogears+unsubscribe@.... For more options, visit this group at http://groups.google.com/group/turbogears?hl=en. |
|
|
Re: how to return csv data?Diez B. Roggisch yazmış:
> On Thursday, July 08, 2010 14:30:10 Timuçin Kızılay wrote: >> there is an easy way in controller methods to return json data, >> @expose('json') >> when I put this expose decorator, it returns json data and this is a >> very nice feature of tg. >> is there anything similar like this for returning csv data? I need to >> return some csv data with header row at the top. Some of my users want >> to get data from the web application as excel files and I did not want >> to dive in to generate an excel file, giving them a csv file will solve >> both ms office and openoffice users problems. >> >> So, is there an example controller method to return csv data? > > @expose(content_type="text/csv") > def get_csv(self, **kwargs): > """ > Returns a *.csv > """ > filename = "test.csv" > the_csv = "a,b,c\n1,2,3" # use module CSV to create this. > response.headers["Content-Disposition"] = "attachment;filename=%s" % > filename > return the_csv > > > Diez > Thank you very much. You saved me hours of pulling my hair out of my head. Thank you, thank you, gracias, tesekkur ederim... -- You received this message because you are subscribed to the Google Groups "TurboGears" group. To post to this group, send email to turbogears@.... To unsubscribe from this group, send email to turbogears+unsubscribe@.... For more options, visit this group at http://groups.google.com/group/turbogears?hl=en. |
|
|
Re: how to return csv data?> the_csv = "a,b,c\n1,2,3" # use module CSV to create this.
e.g. like this @expose(content_type='text/csv') def csv(self): stream = StringIO() writer = csv.writer(stream, dialect='excel') writer.writerow(['Spam'] * 5 + ['Baked Beans']) writer.writerow(['Spam', 'Lovely Spam', 'Wonderful Spam']) output = stream.getvalue() stream.close() return output For creating real Excel files you can use this: http://www.python-excel.org -- Christoph -- You received this message because you are subscribed to the Google Groups "TurboGears" group. To post to this group, send email to turbogears@.... To unsubscribe from this group, send email to turbogears+unsubscribe@.... For more options, visit this group at http://groups.google.com/group/turbogears?hl=en. |
| Free embeddable forum powered by Nabble | Forum Help |