[Twisted-web] Re: [PATCH] nevow.static.File directory
listing
Samuel Reynolds
sam at SpinwardStars.com
Mon Apr 5 10:11:12 MDT 2004
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 ChildPrefixMixin already does the dispatching, and the result
is very extensible and easy to understand.
- Sam
__________________________________________________________
Spinward Stars, LLC Samuel Reynolds
Software Consulting and Development 303-805-1446
http://SpinwardStars.com/ sam at SpinwardStars.com
More information about the Twisted-web
mailing list