How to Serve Binary Files in Webware

  1. Override the writeHTML method of the Page superclass.
  2. Set the necessary HTTP headers:
    • Content type with proper MIME type
    • Disposition with proper file name
  3. Open and deliver the binary data.
from WebKit.Page import Page

class Page_Name(Page):
    def writeHTML(self):
        r = self.response()
        r.setHeader('Content-type', 'application/pdf')
        r.setHeader('Content-disposition', 'attachment; filename=whatever.pdf')
        file = open('/path/to/file', 'rb')
        data =

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s