[Twisted-Python] django with twisted 8.2.x: 2009

Jean-Paul Calderone exarkun at divmod.com
Wed Jan 14 18:00:01 EST 2009

On Wed, 14 Jan 2009 17:48:39 -0500, V S P <toreason at fastmail.fm> wrote:
>wanted to ask for some help in getting django running with
>twisted webserver for my experiments.
>Using Python 2.6
>Twisted 8.2.0
>Django 1.0.2
>on windows xp for now.
>I searched the documentation , most of the blog entries/etc were
>in '07 about this setup.  And most refer to web2 plugin for twisted
>as it support for wsgi.
>I looked at the web2 page on twisted matrix and it said that its
>functionality will be ported back to 'web' module as they become stable.
>I then browsed 'web' module subdirectory and I saw wsgi there
>(and I assume this is what's needed for django).
>So to shorten the story, this is what I tried:
>I downloaded the example web server web.py, made sure it works
>with the test file (and it does).
>Then I added another 'processor' for files with extensions .wpy
>root.processors = {
>            '.cgi': twcgi.CGIScript,
>            '.php3': twcgi.PHP3Script,
>            '.php': twcgi.PHPScript,
>'.wpy':  wsgi.WSGIResource,
>            '.epy': script.PythonScript,
>            '.rpy': script.ResourceScript,
>            '.trp': trp.ResourceUnpickler,

WSGIResource isn't a "processor", so you can't add it to the processors
dictionary like this.

>then I created a simple django file
>------------- views.wpy ------------
>from django.http import HttpResponse
>def hello(request):
>    return HttpResponse("Hello world")

I don't think HttpResponse instances are wsgi applications, nor is that
hello function.

>and tried to run it.  That, of course did not work,
>for one because I did not create a 'resource' global.
>But basically, I do not think I am going right way about it,
>therefore decided to stop and ask.

Take a look at http://code.google.com/p/modwsgi/wiki/IntegrationWithDjango
which explains how to create a Django WSGI application object.

Then, take a look at <http://twistedmatrix.com/trac/attachment/ticket/3510/t.w.wsgi-doc.diff> which is a work-in-progress Twisted documentation
addition which explains how to serve a WSGI application using Twisted Web's
WSGI container.

Once you understand those two pieces, you should be able to combine them
and get a working Twisted Web/Django server.


More information about the Twisted-Python mailing list