[Twisted-Python] Loading pageproducers dynamically

Thomas Weholt 2002 at weholt.org
Tue Jun 24 13:54:34 EDT 2003

I'm porting a project to Twisted where I loaded what was then called
pageproducer, similar to subclasses of Resource in Twisted. They were in a
given folder and located, created an instance of at run time and stored in a
lookup-structure. The files were organized something like this :

[ ... etc ...]

www/index.py maps to index.html, www/folder1/hello1.py to
/folder1/hello.html etc. The main point being that the server didn't know
what classes to import and create before run time. How can I create someting
similar to this, using Resource's putChild etc and keeping the things
discussed lately about keeping python modules out of the webtree ??

I want my users to be able to add pages with ease, not having to edit import
statements in the main modules, put simple doing something like this in a
module named helloworld.py, located in www/test/helloworld.py :

class helloworld(Resource):
    def render(self, request):
        return 'hello world'

and pointing your browser to /test/helloword.py should then show "Hello

Most examples discussed lately has imported all needed modules explicitly at
start up. My setup needs to be more dynamic.


More information about the Twisted-Python mailing list