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

V S P toreason at fastmail.fm
Wed Jan 14 20:48:55 EST 2009


Ok, thank you for the pointers, I got it working
(or at least I get "It worked" django page :-) )

I also used 
http://code.google.com/appengine/articles/django.html
to get a basic wsgi server working

and 
http://www.sitepoint.com/article/build-to-do-list-30-minutes/
to get basic django installation


It ended up pretty painless (sofar)

step 0) install python 2.6.1, twisted 8.2.0 and django 1.0.1

step 1) select a subdirectory as the root of your
twisted wsgi server

step 2) copy in there this file
------------ wsgi_web.py -----------------
import logging, os

# Force Django to reload its settings.
from django.conf import settings
settings._target = None

# Must set this env var before importing any part of Django
os.environ['DJANGO_SETTINGS_MODULE'] = 'mytestproj.settings'


from twisted.web import server 
from twisted.web.wsgi import WSGIResource 
from twisted.python.threadpool import ThreadPool 
from twisted.internet import reactor 

import django.core.handlers.wsgi
import django.core.signals
import django.db
import django.dispatch.dispatcher


def log_exception(*args, **kwds):
  logging.exception('Exception in request:')


def main():
  # Create a Django application for WSGI.
  application = django.core.handlers.wsgi.WSGIHandler()

	 
	 
# Create and start a thread pool, 
# ensuring that it will be stopped when the reactor shuts down 
thread_pool = ThreadPool() 
thread_pool.start() 
reactor.addSystemEventTrigger('after', 'shutdown', thread_pool.stop) 
	 
# Create the WSGI resource 
#wsgi_app_as_resource = WSGIResource(reactor, thread_pool,
basic_wsgi_app) 
wsgi_app_as_resource = WSGIResource(reactor, thread_pool,
django.core.handlers.wsgi.WSGIHandler())       
	 
site = server.Site(wsgi_app_as_resource) 
reactor.listenTCP(8080, site) 
reactor.run()

----------------- end of wsgi_web.py -----------------------


3) your project name will be mytestproj
(and that project directory is relative to the place where
 wsgi_web.py file is started


4) cd to directory where wsgi_web.py is
and run

python.exe <pathtopython>\Lib\site-packages\django\bin\django-admin.py
startproject mytestproj

5) execute 
python.exe   wsgi_web.py


6) from your browser http://localhost:8080  should give you
the django page.


that's it,
Vlad








On Wed, 14 Jan 2009 18:00:01 -0500, "Jean-Paul Calderone"
<exarkun at divmod.com> said:
> On Wed, 14 Jan 2009 17:48:39 -0500, V S P <toreason at fastmail.fm> wrote:
> >Hi,
> >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.
>
> 
> 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.
> 
> Jean-Paul
> 
> _______________________________________________
> Twisted-Python mailing list
> Twisted-Python at twistedmatrix.com
> http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python
-- 
  V S P
  toreason at fastmail.fm

-- 
http://www.fastmail.fm - And now for something completely different┘





More information about the Twisted-Python mailing list