[Twisted-Python] serving up a directory

Clark C. Evans cce at clarkevans.com
Sat Feb 22 22:49:00 MST 2003


On Sun, Feb 23, 2003 at 12:08:33AM -0500, Jp Calderone wrote:
|     app = Application("whatever")
|     ...
|     app.listenTCP(port, siteInstance)
|     app.listenTCP(anotherPot, smtpServerFactory)
|     ...
|     app.run(save=0)

Thanks Jp

...

I think I found an unexpected behavior in putChild and 
the Redirect resource, here is my code snippet...


class Redirect(static.Redirect):
    def __init__(self, url):
        resource.Resource.__init__(self)
        self.url = url

def run():
    root = Resource()
    root.putChild("dynamic",MyDynamicResource())
    root.putChild("",Redirect("/static/"))
    root.putChild("static",static.File("/my/static/content"))
    site = server.Site(root)
    reactor.listenTCP(8081,site)
    reactor.run()


Anyway, first, I found the "Redirect" resource not to 
behave as expected... for some reason it wanted a request?!
for the argument of __init__ instead of a url. 

But second, and most importantly, I wanted to have my
static content served from the root (without the redirect); 
I initally tried:

    root.putChild("",static.File("/my/static/content"))

But unfortunately, this introduced two slashes after
the server, ie,  http://server//index.html which 
causes problems down the line.  Above was my current
work-aroud (using a redirect to a sub-folder).  However,
ideally, I'd like the above putChild to work as expected
and not to introduce the double slashes.   

I looked into the Rewrite resource for a while, but I 
couldn't find any examples and it wasn't obvious how
to use it (it's also getting late)

Regardless, this toolset is splendid; that I've gotten
this far (ported a rather complicated mod_python program
in less than 8 hours) is quite impressive indeed.  Now
the last bit... getting the database pooling to work!

Thank you so much,

;) Clark




More information about the Twisted-Python mailing list