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 [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/turbogears?hl=en.