Using StaticFileHandler to host a file on Tornado Python -


hi attempting use staticfilehandler in tornado , part working, except outputting file (.csv) in webpage when click download. way can save file right clicking , saying save target (but doesn't work in browsers).

how can force file downloaded? know need somehow set header of staticfilehandler this:

    self.set_header('content-type','text-csv')     self.set_header('content-disposition','attachment') 

but have no idea how set because default handler.

thanks time!

extend web.staticfilehandler

class staticfilehandler(web.staticfilehandler):     def get(self, path, include_body=true):         if [some csv check]:             # code above, or else custom want             self.set_header('content-type','text-csv')               self.set_header('content-disposition','attachment')          super(staticfilehandler, self).get(path, include_body) 

dont forget use extended class in handler!


Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -