0

I'm having troubles using zope. I just need to serve to the client a xls file created with python xlwt module but I don't find the way to do that.

In my .pt file I have a button that calls a .py function, this function creates correctly the file, but it doesn't serve it to the client browser. I'm trying in this way:

f = open(temp_file, 'rb').read()
self.request.response.setHeader('Content-Type', 'application/vnd.ms-excel')
self.request.response.setHeader('Content-Disposition',' attachment; filename=Excel_Workbook.xls')
return f

How can I do that?

Thanks everybody!

  • Are you open to using a browser view to do this? I do this with a browser view and a custom "file stream iterator" that uses (and disposes of when done) temp files. – sdupton Jun 07 '12 at 17:31

1 Answers1

0

How are you calling the script? You need to invoke it directly from a URL, not from your template.

Include a download URL in your template that points to your python script:

<a href="http://yoursite/path/to/script">Download an Excel spreadsheet</a>
Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343