SitePage

When building a WebKit application, you should always create an abstract SitePage class from which all your other Page classes inherit. This allows you to build site-specific conveniences, utilities, etc. that will be accessible to all pages.

Create a file named SitePage.py with these contents:

from WebKit.Page import Page

class SitePage(Page):
    pass

In your concrete page classes, inherit SitePage:

from SitePage import SitePage

class MyPage(SitePage):

    def writeContent(self):
        self.writeln('Hello')

As you develop your website you will think of utility methods that you commonly want access to. For example, I often have a utility method called fragment() which given a name, loads an HTML fragment file from disk for my use. Here is a simple example:

def fragment(self, name):
    filename = '%s/../Fragments/%s.htmlf' % (__file__, name)
    return open(filename).read()

Now all your pages can pull in fragments such as: self.fragment('Header')

See FragmentsRecipe for more information on that particular technique.

Also, you shouldn't put files that are abstract or private in your public context where they could be susceptible to hacking. That means your SitePage will go into a directory often named Lib and your imports will look like this:

from Lib.SitePage import SitePage

See DirectoryStructure for details.

-- ChuckEsterbrook - 27 Oct 2001