How to start a local Tornado web server?

Is it possible to start Tornado so that it listens on the local port (for example, localhost: 8000). I can't seem to find documentation explaining how to do this.

+8
python tornado
source share
4 answers

Add the address argument to Application.listen () or HTTPServer.listen ().

It is described here (Application.listen) and (TCPServer. Listen) .

For example:

application = tornado.web.Application([ (r'/blah', BlahHandler), ], **settings) # Create an HTTP server listening on localhost, port 8080. http_server = tornado.httpserver.HTTPServer(application) http_server.listen(8080, address='127.0.0.1') 
+22
source share

In a document that is mentioned to run on a specific port, for example

 import tornado.ioloop import tornado.web class MainHandler(tornado.web.RequestHandler): def get(self): self.write("Hello, world") application = tornado.web.Application([ (r"/", MainHandler), ]) if __name__ == "__main__": application.listen(8000) tornado.ioloop.IOLoop.instance().start() 

You will get additional help http://www.tornadoweb.org/documentation/overview.html and http://www.tornadoweb.org/documentation/index.html

+2
source share

Once you have defined the application (e.g. in other answers) in a file (e.g. server.py), you just save and run this file.

python server.py

+1
source share

If you want to demonize a tornado, use supervisord. If you want to access the tornado at an address like http://mylocal.dev/ , you should look at nginx and use it as a reverse proxy. And on a specific port, you can bind it, as in Lafada's answer.

0
source share

All Articles