Question

I'm looking to add/serve a complicated django application, to an existing twisted server (the existing twisted server doesn't serve any http services, at least not on the standard ports, so I can use port 80 for this work).

All of the examples I can find to date are for earlier versions of twisted, and do not seem to work, out of the box, with the latest version.

Where can I find an up to date tutorial, set of examples or recipe, showing the correct wiring for serving a complex Django application through the latest version of twisted?


More specifically, I have gotten close with this little blurb:

from twisted.web.resource import Resource
from twisted.web import wsgi
from twisted.internet import reactor
from django.core.handlers.wsgi import WSGIHandler
os.environ['DJANGO_SETTINGS_MODULE'] = 'app.settings'
django_application = WSGIHandler()
django_resource = wsgi.WSGIResource(reactor, reactor.getThreadPool(), django_application)

root = Resource()
root.putChild("",django_resource)
from twisted.application import service
application = service.Application("app")

internet.TCPServer(8080, Site(root)).setServiceParent(application)

(it will serve the basic contents of my django project, but seems to fail to properly serve my static content, and doesn't seem to automatically handle django applications served at subdirectories within my project)

Was it helpful?

Solution

Found my bug:

# All this work is un-necessary overkill
#root = Resource()
#root.putChild("",django_resource)
#from twisted.application import service
#application = service.Application("app")

internet.TCPServer(8080, Site(django_resource)).setServiceParent(application)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top