【问题标题】:Django as middleware in a tornado appDjango 作为龙卷风应用程序中的中间件
【发布时间】:2011-04-12 22:05:19
【问题描述】:

我正在尝试运行 tornadio(python 的 socket.io)来使用 django。有没有办法在 tornado 中做这样的事情(将 django 作为中间件运行),或者我可以从 django 中访问 tornado(取消注释第二个应用程序定义路由直接到 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()

【问题讨论】:

    标签: python django wsgi tornado socket.io


    【解决方案1】:

    我会考虑使用这个项目来提供帮助: https://github.com/koblas/django-on-tornado

    它是 tornado 和 django 的集成,让您可以这样做:

    python manage.py runtornado --reload 8888
    

    包括一个使用 django 和 tornado 构建的示例聊天服务。

    【讨论】:

      猜你喜欢
      • 2013-05-09
      • 1970-01-01
      • 1970-01-01
      • 2012-03-18
      • 1970-01-01
      • 2011-10-27
      • 1970-01-01
      • 1970-01-01
      • 2022-06-16
      相关资源
      最近更新 更多