Python tornado build webserver

Source: Internet
Author: User

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

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.