Tornado study notes, tornado
Import tornado. ioloopimport tornado. webclass MainHanlwe (tornado. web. requestHandler): def get (self): login_user = self. get_secure_cookie ('login _ user', None) if login_user: self. write (login_user) else: self. redirect ('/login') class LoginHanmder (tornado. web. requestHandler): def get (self): # self. current_user () self.render('login.html ', ** {'statue': ''}) def post (self, * args, ** kwargs): username = self. get_argument ('name') password = self. get_argument ('pwd') print (username, password) if username = 'liwanlei' and password = '000000': self. set_secure_cookie ('login _ user', 'leizi') self. redirect ('/Index') else: self.render('login.html', ** {'status': 'username or password error'}) class MainHandler (tornado. web. requestHandler): def get (self): self.render('shangchuan.html ') def post (self, * args, ** kwargs): file = self. request. files ['fff'] for mes in file: file_name = mes ['filename'] with open (file_name, 'wb') as up: up. write (mes ['body']) class Maiandler (tornado. web. requestHandler): def get (self): self.render('yan.html ') def post (self, * args, ** kwargs): obj = MainForm () result = obj. check_valid (self) self. write ('OK') setting = {'template _ path': 'template', 'static _ path': 'static ', 'static _ url_prefix ': '/static/', 'cookie _ secret': 'aiuasdhflashjdfoiuashdfiu', 'xsrf _ cooki': True} application = tornado. web. application ([(r "/index", Maiandler), (r "/login", LoginHanmder),], ** setting) if _ name __= = '_ main _': application. listen (1, 5000) tornado. ioloop. IOLoop. instance (). start ()
<Html>
<! DOCTYPE html>