码迷,mamicode.com
首页 > 其他好文 > 详细

tornado 学习笔记

时间:2017-07-29 21:29:22      阅读:153      评论:0      收藏:0      [点我收藏+]

标签:ati   flash   上传   text   user   pre   war   loop   and   

import  tornado.ioloop
import  tornado.web
class 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 ==123:
            self.set_secure_cookie(login_user,leizi)
            self.redirect(/index)
        else:
            self.render(login.html,**{status:用户名或者密码错误})
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: aiuasdhflashjdfoiuashdfiuh,
    xsrf_cookie:True
}
application=tornado.web.Application([
    (r"/index", Maiandler),
    (r"/login", LoginHanmder),
],**setting)
if __name__==__main__:
    application.listen(5000)
    tornado.ioloop.IOLoop.instance().start()
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
    <title>上传文件</title>
</head>
<body>
    <form id="my_form" name="form" action="/index" method="POST"  enctype="multipart/form-data" >
        <input name="fff" id="my_file"  type="file" />
        <input type="submit" value="提交"  />
    </form>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
{%if status %}
{{status}}
{% end %}
<form action="" method="post">
    <input type="text" name="name">
    <input type="password" name="pwd">
    <input type="submit" value="登录">
</form>
</body>
</html>

  

tornado 学习笔记

标签:ati   flash   上传   text   user   pre   war   loop   and   

原文地址:http://www.cnblogs.com/leiziv5/p/7257455.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!