Tornado is very simple to build, use Pip, or download source code can be.
Let's look at one of the simplest programs:
ImportTornado.ioloopImportTornado.webclassMainHandler (tornado.web.RequestHandler):defGet (self): Self.write ("") Application= Tornado.web.Application ([(R"/", MainHandler),])if __name__=='__main__': Application.listen (8888) tornado.ioloop.IOLoop.instance (). Start ()
We run this program and open the browser input:
http://localhost:8888/
You can see the bold HelloWorld.
So what does this piece of code mean:
Let's look first.
class MainHandler (Tornado.web.RequestHandler): def Get (self): self.write ("Hello,World")
This defines a processor that defines a GET method that corresponds to a GET request in the HTTP protocol.
Then it is:
application = Tornado.web.Application ([ (R"/", MainHandler),] )
The implication here is that if the user enters a path that is "/", that is, the root path, then the MainHandler we have just written will be used, if the request uses a GET, then call MainHandler's Get method, if it is a POST request, To call the Post method in MainHandler.
So we enter the above URL, tornado called the Get method in MainHandler, return "
Preliminary use of the Python Tornado framework-hello,world