The Python Tornado framework uses

Source: Internet
Author: User

Processing Method t_handler.py

 fromTornado.webImportRequestHandlerclassIndexhandler (requesthandler):defGet (self): name=self.get_argument ('name',' World') Self.write ('Hello'+name)classAddHandler (requesthandler):defGet (self): Val1=self.get_argument ('Val1', 0) val2=self.get_argument ('Val2', 0) Val3=int (VAL1) +Int (val2) self.write (str (VAL3) )classMinushandler (requesthandler):defGet (self): Val1=self.get_argument ('Val1', 0) val2=self.get_argument ('Val2', 0) Val3=int (VAL1)-Int (val2) self.write (str (VAL3) )

URL path, processing method correspondence relationship t_url.py

 from import *URL=[(R'/', Indexhandler), (R' ) /page1 ' , AddHandler), (R'/page2', Minushandler)]

Start Process t_tornado.py

tornado.optionsImportTornado.web fromTornado.optionsImportdefine,optionsImportT_urldefine ("Port", default=8000,help="run on port", type=int)if __name__=="__main__": Tornado.options.parse_command_line ()#initializing the web frameworkapp=tornado.web.Application (T_url.url)#Open port Monitoring serviceHttp_server=tornado.httpserver.HTTPServer (APP) Http_server.listen (Options.port)#Start the service processTornado.ioloop.IOLoop.instance (). Start ()

Operation Result:

Browser Access results:

Python tornado framework uses

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.