Craig
Craig

Reputation: 7671

Django as middleware in a tornado app

I am trying to run tornadio (socket.io for python) to work with django. Is there are way to do something like this in tornado (running django as middleware), or can I access tornadio from within django (uncommenting the second application definition routes straight to django):

#!/usr/bin/env python
import os
import tornado.httpserver
import tornado.ioloop
import tornado.wsgi
import sys
sys.path.append('..')

class MainHandler(tornado.web.RequestHandler):
    def get(self):
        self.write("Hello, world")

os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'
import django.core.handlers.wsgi

wsgi = django.core.handlers.wsgi.WSGIHandler()
django_container = tornado.wsgi.WSGIContainer(wsgi)

application = tornado.web.Application([
    (r"/", MainHandler),
    django_container
])
# application = django_container

tornado.httpserver.HTTPServer(application).listen(8888)
tornado.ioloop.IOLoop.instance().start()

Upvotes: 3

Views: 1681

Answers (1)

koblas
koblas

Reputation: 27098

I would look at using this project to help: https://github.com/koblas/django-on-tornado

It an integration of tornado and django allowing you to do this:

python manage.py runtornado --reload 8888

Included is a sample chat service built using django and tornado.

Upvotes: 2

Related Questions