1. Install tornado, I use the Windows environment
Download tornado on the Tornado website:
Https://pypi.python.org/packages/source/t/tornado/tornado-4.2.tar.gz
Decompression tornado-4.2.tar.gz
Execute the command in the extracted tornado-4.2 folder:
Python setup.py Install
Complete the installation.
2. Official Learning Documents
Http://www.tornadoweb.org/en/stable/guide/intro.html
Http://www.tornadoweb.cn/documentation
3. Study Notes
The most basic method of post and get implementation
#-*-Coding:utf-8-*-ImportTornado.ioloopImporttornado.webhtml ="' <form method=" POST "name=" Frm1 "action="/login "> <label for=" txt "> User name </label> <input typ E= "text" id= "txtname" name= "myname" ><br/><br/> <label for= "txt" > Password </label> <input ty Pe= "text" id= "txtpwd" name= "MyPwd" ><br/><br/> <input type= "Submit" ></form> " class basehandler(tornado.web.RequestHandler): def get_current_user(self): returnSelf.get_secure_cookie ("User") class mainhandler(basehandler): def get(self): if notSelf.current_user:self.redirect ("/login")returnName = Tornado.escape.xhtml_escape (self.current_user) Self.write ("Hello,"+ name) class loginhandler(basehandler): def get(self):Self.write (HTML) def post(self):Self.set_secure_cookie ("User", Self.get_argument ("MyName"))# self.write ("POST LOGIN")Self.redirect ("/") settings = Dict (# Template_path=template_path, # Static_path=static_path, # Cookie_secret=str (Uuid.uuid1 ()),cookie_secret="61oetzkxqagaydkl5gemgejjfuyh7eqnp2xdtp1o/vo=", login_url="/login",# gzip=true, # xheaders=true,debug=True) application = Tornado.web.Application ([(r "/", MainHandler), (r "/login", Loginhandler)], **settings)if__name__ = ="__main__": Application.listen (8888) Tornado.ioloop.IOLoop.current (). Start ()
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Python tornado build webserver