[Twisted-web] Re: [PATCH] nevow.static.File directory listing

Matt Goodall matt at pollenation.net
Mon Apr 5 14:03:08 MDT 2004

On Mon, 2004-04-05 at 17:11, Samuel Reynolds wrote:
> At 2004-04-05 09:48 AM +0100, you wrote:
> >static.File will publish individual files or an entire
> >directory structure. It is up to you how you use it but for 'images',
> >'stylesheets', 'scripts' etc I tend to find it easier to publish a
> >directory for each.
> This is what I do, as well. My app module is organized as:
> page
>      [page renderers]
>      css [CSS files]
>      help [HTML and supporting files]
>      image [image files used in rendered pages]
>      javascript [javascript files]
>      templates [templates for page renderers]
> misc [whatever wouldn't fit in the others]
> db [persistence]
> sql [sql for DB initial set, etc.]
> scripts [utilities for setup, etc.]
> The app has a start/welcome page, with URL 'children' for CSS,
> help, image, and Javascript. The page class (an HTMLRenderer)
> defines:
>      cssDirectory = os.path.join(os.path.split(__file__)[0], "css")
>      helpDirectory = os.path.join(os.path.split(__file__)[0], "help")
>      imageDirectory = os.path.join(os.path.split(__file__)[0], "image")
>      jsDirectory = os.path.join(os.path.split(__file__)[0], "javascript")
>      def child_css( self, request ):
>          return static.File( self.cssDirectory, defaultType="text/css" )
>      def child_help( self, request ):
>          return static.File( self.helpDirectory, defaultType="text/html" )
>      def child_image( self, request ):
>          return static.File( self.imageDirectory, defaultType="image/gif" )
>      def child_js( self, request ):
>          return static.File( self.jsDirectory, defaultType="text/javascript" )
> I'm not sure how efficient this is, but it certainly works well.

The advantage to using class attributes is that the child resources are
only created once as there is often only one RootPage created for the
application. Using child_ methods is useful when the resource needs to
be initialised with args that are only known at request time.

Cheers, Matt

Matt Goodall, Pollenation Internet Ltd
w: http://www.pollenation.net
e: matt at pollenation.net

Any views expressed are my own and do not necessarily reflect
the views of my employer.

More information about the Twisted-web mailing list