Use tornado as a server for your Django app

Source: Internet
Author: User

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。发现需要的代码是相当精简的。
    • 1
    • 2
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())
    • 1
    • 2

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
    • 1

Replace with get_wsgi_application .
Haha, OK,python tonado_main.py ran him up.

Use tornado as a server for your Django 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.