[Twisted-web] Serving different resource types from the same directory

Eric Faurot eric.faurot at gmail.com
Sun Nov 27 10:30:58 MST 2005


On 11/27/05, Olivier Laurent <olilau.list.1 at gmail.com> wrote:

> Here is how I tried:
>
> # [...]
>
> PATH = '/var/www/'
>
> pt_resource = static.File(PATH)
> pt_resource.processors = { '.pt' : PTResource }
> pt_resource.indexNames = [ 'index' + '.pt' ]
>
> rst_resource = static.File( PATH )
> rst_resource.processors = { '.rst' : RSTResource }
> rst_resource.indexNames = [ 'index' + '.rst' ]
>
> #root = Resource() # I tried this too
> root = static.File(PATH)
>
> root.putChild(PATH, pt_resource)
> root.putChild(PATH, rst_resource)

The point of the resource name is to differenciate it from its siblings.
If you give the same name to both of course it does not work.
Moreover, I don't think '/var/www/' a valid resource name.
Either use different "logical" names for each File, or use different
processors for a single File.

I think you want something like:

my_resource = static.File(PATH)
my_resource.processors = { '.pt' : PTResource,  '.rst' : RSTResource}
my_resource.indexNames = [ 'index.pt',  'index.rst' ]
root.putChild('foo', my_resource)


Eric.


More information about the Twisted-web mailing list