Combination of Tornado and Django using Tornado Server for Django WSGI APP

Source: Internet
Author: User

#!/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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.