#!/usr/bin/env python#Run this with#serves by default at#Http://localhost:8080/hello-tornado and#Http://localhost:8080/hello-django fromTornado.optionsImportoptions, define, Parse_command_lineImportDjango.core.handlers.wsgiImportTornado.httpserverImportTornado.ioloopImportTornado.webImportTornado.wsgiImportOsdefine ('Port', Type=int, help="run on the given port", default=80)classHellohandler (tornado.web.RequestHandler):defGet (self): Self.write ('Hello from Tornado')defMain (): 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") ifDjango. VERSION[1] > 5: Django.setup () Main ()
└──ts directory structure, project name 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
Qingming Festival ~ ~
Chinese Traditional festivals, noon in dormitory
Tomorrow will be class again, come on Oh!
Reference Documentation:
Official documents
Https://github.com/bdarnell/django-tornado-demo
Combination of Tornado and Django using Tornado Server for Django WSGI APP