Idle to nothing, tossing and tossing.
I've always heard that Tonado is an asynchronous web framework and server, as a framework, but the server is not very understanding. So decide to understand, since you can do the server, then put your own Django app to the top.
先是*Google*了一下,找到了一篇相关[博客](https://thinkfaster.co/2015/01/run-django-on-tornado/)。于是乎,将其改造改造,直接搬过来。原作是要用*websocket*这个东东,而我只是要App部署上去就OK。发现需要的代码是相当精简的。
Import Osos.environ.setdefault ("Django_settings_module","Myblog.settings")Import django.confImport Django.contrib.authImport Django.core.handlers.wsgiFrom Django.core.wsgiImport Get_wsgi_applicationImport django.dbImport Tornado.httpserverImport Tornado.ioloopImport Tornado.webImport Tornado.wsgiFrom Tornado.optionsImport options, Definedefine (' Port ', Type=int, default=8080)ClassHellohandler (Tornado.web.RequestHandler): def get ' Hello From tornado ') def main (): Wsgi_app = Tornado.wsgi.WSGIContainer (Get_wsgi_application ()) Tornado_app = Tornado.web.Application ([r '/hello-tornado* ', Hellohandler), ( r '. * ', Tornado.web.FallbackHandler, Dict (Fallback=wsgi_app)),]) Server = Tornado.httpserver.HTTPServer (Tornado_app) Server.listen (options.port, Address= 192.168.1.59 ') tornado.ioloop.IOLoop.instance (). Start () if __name__ = ' __main__ ': Main ()
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21st
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
There are some changes in the Wsgicontainer , the original use is:
wsgi_app = tornado.wsgi.WSGIContainer( django.core.handlers.wsgi.WSGIHandler())
Then you use the error, the translation infrastructure cannot be initialized before the apps registry are ready. Check that you don Non-lazy GetText calls at import time I'm going to go.
I found it in the end.
from django.core.wsgi import get_wsgi_application
Replace with get_wsgi_application .
Haha, OK,python tonado_main.py ran him up.
Use tornado as a server for your Django app