Hi, i have a problem to display the CSV file stored in the table.the code below is in controllerdef view_performance():files = db.Pass_Configuration(request.args(0, cast=int)) or redirect(URL('index')) // get the ID of Pass_Configuration table form the URLreturn dict(files=files)def download():return response.download(request, db) //download functionthe code in the View as follows{{extend 'layout.html'}}<h1>{{='Performance'}}</h1><br>src="{{=URL('download', args=files.PerformanceFile)}}"
i know i get the path to the file right but somehow it does not display the CSV file. it just displays the file path and nothing else. i know i am missing something but could not figure outcould you please help me to point out what the mistake i have and how to fix it. thanks
filedata=open(dst,"rb").read()
response.headers['Content-Type']='image/jpeg'
response.headers['Content-Length']=imstat.st_size
return response.stream(cStringIO.StringIO(filedata))
--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to the Google Groups "web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to web2py+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/web2py/a157283a-534f-44f9-8861-763768f0c6ca%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Hi DaveCould you please show me more detail in code since i need to download the CSV file store in the table?
get query
set headers # it does 'Content-disposition' as well as 'Content-Type'
return str(db(query, filters).select())
On Tuesday, May 28, 2019 at 11:00:42 PM UTC-7, Quang Lam wrote:
Hi, i have a problem to display the CSV file stored in the table.the code below is in controllerdef view_performance():files = db.Pass_Configuration(request.args(0, cast=int)) or redirect(URL('index')) // get the ID of Pass_Configuration table form the URLreturn dict(files=files)def download():return response.download(request, db) //download functionthe code in the View as follows{{extend 'layout.html'}}<h1>{{='Performance'}}</h1><br>src="{{=URL('download', args=files.PerformanceFile)}}"
[...]
You may not want the 'Content-disposition' header -- it's setting attachment and filename.
[...]
But CSV is an ugly thing to show to a user; if the user needs query results in a table, then either SQLTABLE or SQLFORM.grid could be used, and I think the latter could also be used for a file you read.
--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to the Google Groups "web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to web2py+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/web2py/01c09fd7-5694-4afa-885f-4c3136eab0b2%40googlegroups.com.
try:
import StringIO
except ImportError:
from io import StringIO
def download_csv():
stream = StringIO.StringIO()
db.export_to_csv_file(stream,
delimiter = ',',
quotechar = '"',
write_colnames = True,
represent = False)
response.headers['Content-Type'] = 'text/csv'
response.headers['Content-Disposition'] = 'inline; filename="{0}.csv"'.format(request.function.replace('_', ' ').title() )
return stream.getvalue()To view this discussion on the web visit https://groups.google.com/d/msgid/web2py/CAKDykLhfGFRBZi%3DW5NmqONbynTXbfaMF966kU_QnTNkHPgvb-A%40mail.gmail.com.