Django 作为龙卷风应用程序中的中间件
我正在尝试运行tornadio(用于python的socket.io)来与django一起使用。有没有办法在tornado中执行类似的操作(将django作为中间件运行),或者我可以从django中访问tornadio(取消注释第二个应用程序定义直接路由到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()
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()
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我会考虑使用这个项目来帮助:
https://github.com/koblas/django-on-tornado
它集成了Tornado 和 django 允许您执行此操作:
其中包含使用 django 和 Tornado 构建的示例聊天服务。
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:
Included is a sample chat service built using django and tornado.