<br><br><div><span class="gmail_quote">On 2/9/06, <b class="gmail_sendername">James Y Knight</b> <<a href="mailto:foom@fuhm.net">foom@fuhm.net</a>> wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
> from twisted.application import strports, service<br>> from twisted.web2 import static, server, http, wsgi, resource<br>><br>> import sys<br>> sys.path.append("./myproject")<br>> from django.core.handlers.wsgi
import WSGIHandler<br>> import os<br>> os.environ['DJANGO_SETTINGS_MODULE'] = 'myproject.settings'<br>><br>> class toplevel(wsgi.WSGIResource):<br>><br>><br>> def child_media(self, ctx):<br>> return
static.File("./myproject/media")<br>><br>><br>> root = toplevel(WSGIHandler())<br>> application = service.Application("web")<br>> site = server.Site(root)<br>> s = strports.service('tcp:8000',
http.HTTPFactory(site))<br>> s.setServiceParent(application)<br><br>That won't work -- what you want is to nest the resources rather than<br>subclass them. Something like this resource should do you (untested,<br>wrote in email client). It says: if the path starts with media,
<br>return the static File and pass it the remaining pieces of the path,<br>otherwise pass the entire path onto wsgi for its processing.<br><br>class toplevel(object):<br> implements(IResource)<br><br> def __init__(self):
<br> self.wsgi = wsgi.WSGIResource(WSGIHandler())<br> self.media = static.File("./myproject/media"<br><br> def locateChild(self, req, segs):<br> if segs[0] == 'media':<br> return self.media, segs[1:]
<br> return self.wsgi, segs<br><br> def renderHTTP(self, req):<br> return self.wsgi<br><br>James<br><br>_______________________________________________<br>Twisted-web mailing list<br><a href="mailto:Twisted-web@twistedmatrix.com">
Twisted-web@twistedmatrix.com</a><br><a href="http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-web">http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-web</a><br></blockquote></div>The final solution I came up with is..
<br>
<br>
from twisted.application import strports, service<br>
from twisted.web2 import static, server, http, wsgi, resource<br>
<br>
import sys<br>
sys.path.append("./myproject")<br>
from django.core.handlers.wsgi import WSGIHandler<br>
import os<br>
os.environ['DJANGO_SETTINGS_MODULE'] = 'myproject.settings'<br>
<br>
wsgi = wsgi.WSGIResource(WSGIHandler())<br>
<br>
root = wsgi<br>
application = service.Application("web")<br>
site = server.Site(root)<br>
s = strports.service('tcp:8000', http.HTTPFactory(site))<br>
s.setServiceParent(application)<br>
<br>
media = static.File("./myproject/media")<br>
site2 = server.Site(media)<br>
m = strports.service('tcp:8080', http.HTTPFactory(site2))<br>
m.setServiceParent(application)<br>
<br>
But what you show is awesome, been looking at how to do something like
that. Thanks for all the help, this issue is officially solved.. <br>
<br>
ToddB<br>