On Tuesday, November 15, 2016 at 3:41:39 AM UTC-8, lucas wrote: > > ok, with dave's prompting and help, i got the code to work. i don't > understand why taking the response.write() function out there works. how > come? > > here is my working snippet: > > from cStringIO import StringIO > stream = StringIO() > if (file_return == 'xml'): > from gluon.serializers import xml > stream.write(xml(dct)) > response.headers['Content-Type'] = 'text/xml; > charset=us-ascii' > response.headers['Content-disposition'] = 'attachment; > filename=hsDNA_%s_IQa.xml' % (qry[0][1]) > return stream.getvalue() > else: > stream.write(r"%s" % dct) > response.headers['Content-Type'] = 'text/plain; > charset=us-ascii' > response.headers['Content-disposition'] = 'attachment; > filename=hsDNA_%s_IQa.py' % (qry[0][1]) > return stream.getvalue() > > i got rid of the csv option and just went with xml and python. both are > working great. > > thanx dave, lucas >
Good to hear you're good to go. FWIW, I had little trouble transplanting the appadmin example into my csv test program. def getcsv(): import gluon.contenttype response.headers['Content-Type'] = \ gluon.contenttype.contenttype('.csv') query = db.uptable(id > 0) response.headers['Content-disposition'] = 'attachment; filename=%s_%s.csv'\ % tuple(request.vars.where.split('.')[:2]) return str(db(query, ignore_common_filters=True).select(db.uptable.id,db .uptable.something)) (Yes, I really do have a field called "something" ... it is a test program, after all) theurl/getcsv?where=fiddle.x gets turned into fiddle_x.csv, in a minor tweak of appadmin's attempt to get the table name. /dps -- 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+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.