[Twisted-web] Web2 Script.py seems to be broken

Todd Thomas caliban19 at gmail.com
Thu Feb 9 01:45:25 MST 2006


On 2/9/06, Todd Thomas <caliban19 at gmail.com> wrote:
>
>
>
> On 2/8/06, Todd Thomas <caliban19 at gmail.com> wrote:
> >
> >
> >
> > On 2/8/06, David Reid < dreid at dreid.org> wrote:
> > >
> > > Todd Thomas wrote:
> > > > It does support wsgi, I was playing around with it. I went back to
> > > > twisted-web, I like its lower level approach. Using http.request
> > > > directly vs. resources is nice since I can pretty much tell exactly
> > > what
> > > > is going on. I love the fact that you can work at an extremely low
> > > level
> > > > in twisted-web. I hope twisted-web2 doesn't get too high level.
> > >
> > > I don't really understand this, twisted.web _has_ resources.  They're
> > > not very good in that one resource is expected to return another
> > > resource to consume the next segment in the path, which makes it hard
> > > to
> > > stop the machinery.  But if you mean what I think you mean (which I
> > > hope
> > > you don't) and that you're working with your own server.Site then I'd
> > > say you need twisted.web2 more than anyone, because it's resource api
> > > will allow you to make your framework work along side others.  Which
> > > is
> > > one of the problems with current Nevow and part of the reason
> > > twisted.web2 was started.
> > >
> > > -David
> > >
> > >
> > > _______________________________________________
> > > Twisted-web mailing list
> > > Twisted-web at twistedmatrix.com
> > > http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-web
> > >
> > You just described exactly the problem I am currently having with
> > twisted-web2. I tried to create wsgi as a root resource, however its also
> > dependent on static files in media directory. I wasn't able to create a
> > child object due to no matter what it passes full path to the wsgi
> > application. So then I made it a child of a root resource, this sort of
> > worked. But since the root path was consumed when it is passed to the child
> > resource, when the application does a redirect, it creates the url in
> > relation to root, not the child url. In my own application I could work
> > around this without too much difficulty since I already know where my child
> > is in relation to the root object.
> >
> Okay, I seemed to have solved most of my problems. Only issue having now
> is pysqlite2 doesn't like being called from threads seperate from the ones
> that created it. It could be run as a deferred in this case since it does
> respond pretty quick. But I am sure could solve this issue simply by
> changing to mysql or postgresql. The solution was stupidly simple.
>
> from twisted.application import strports, service
> from twisted.web2 import static, server, http, wsgi, resource
>
> import sys
> sys.path.append("./myproject")
> from django.core.handlers.wsgi import WSGIHandler
> import os
> os.environ['DJANGO_SETTINGS_MODULE'] = 'myproject.settings'
>
> class toplevel(wsgi.WSGIResource):
>
>
>     def child_media(self, ctx):
>         return static.File("./myproject/media")
>
>
> root = toplevel(WSGIHandler())
> application = service.Application("web")
> site = server.Site(root)
> s = strports.service('tcp:8000', http.HTTPFactory(site))
> s.setServiceParent(application)
>
>
> It works fairly well, or would if I wasn't testing on windows. Before you
> ask why windows. I have box I dual boot into and normally run secure shell
> to, using ubuntu linux currently. Unfortunately my computer has sims 2 on
> which my g/f has been playing religiously lately. So I am stuck using
> windows at work for right now.
>
> ToddB
>
I was wrong, the css and js were cached, media directory is unreachable
using this code. Which I thought it would be since
wsgi.WSGIResourceimplements its own locate child. Any ideas of
something that could work?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://twistedmatrix.com/pipermail/twisted-web/attachments/20060209/455a6129/attachment.htm


More information about the Twisted-web mailing list