开发者

Django as middleware in a tornado app

开发者 https://www.devze.com 2023-02-25 16:16 出处:网络
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 djang

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.i开发者_C百科nstance().start()


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消