zoukankan      html  css  js  c++  java
  • tornado和django的结合使用 tornado Server for django WSGI APP

    #!/usr/bin/env python
    
    # Run this with
    # Serves by default at
    # http://localhost:8080/hello-tornado and
    # http://localhost:8080/hello-django
    
    from tornado.options import options, define, parse_command_line
    import django.core.handlers.wsgi
    import tornado.httpserver
    import tornado.ioloop
    import tornado.web
    import tornado.wsgi
    import os
    define('port', type=int, help="run on the given port", default=80)
    
    class HelloHandler(tornado.web.RequestHandler):
      def get(self):
        self.write('Hello from tornado')
    
    def main():
      parse_command_line()
      wsgi_app = tornado.wsgi.WSGIContainer(
        django.core.handlers.wsgi.WSGIHandler())
      tornado_app = tornado.web.Application(
        [
          ('/hello-tornado', HelloHandler),
          ('.*', tornado.web.FallbackHandler, dict(fallback=wsgi_app)),
          ])
      server = tornado.httpserver.HTTPServer(tornado_app)
      server.listen(options.port)
      tornado.ioloop.IOLoop.instance().start()
    
    if __name__ == '__main__':
      os.environ.setdefault("DJANGO_SETTINGS_MODULE", "YOUR_PROJECT_NAME.settings")
      if django.VERSION[1] > 5:
        django.setup()
      main()

    └── ts 目录结构,项目名称ts ├── manage.py ├── tornado_main.py ├── tornado_main.py~ └── ts ├── __init__.py ├── __init__.pyc ├── manage.py ├── settings.py ├── settings.py~ ├── settings.pyc ├── tornado_main.py ├── tornado_main.py~ ├── urls.py ├── urls.py~ ├── urls.pyc ├── views.py ├── views.pyc └── wsgi.py

    清明节~~~~

    中国传统节日,中午在宿舍

    明天又要上课了,加油哦!

    参考文档:

    官方文档

    https://github.com/bdarnell/django-tornado-demo

  • 相关阅读:
    【Codechef】Chef and Bike(二维多项式插值)
    USACO 完结的一些感想
    USACO 6.5 Checker Challenge
    USACO 6.5 The Clocks
    USACO 6.5 Betsy's Tour (插头dp)
    USACO 6.5 Closed Fences
    USACO 6.4 Electric Fences
    USACO 6.5 All Latin Squares
    USACO 6.4 The Primes
    USACO 6.4 Wisconsin Squares
  • 原文地址:https://www.cnblogs.com/learn-to-rock/p/5352033.html
Copyright © 2011-2022 走看看