Preliminary use of the Python Tornado framework-hello,world

Source: Internet
Author: User

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

Related Article

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.