zoukankan      html  css  js  c++  java
  • tornado 学习笔记

    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>
    

      

  • 相关阅读:
    【每日更新】全栈笔记
    【SQL模板】四.插入/更新 列模板TSQL
    【SQL模板】三.插入/更新 数据模板TSQL
    【SQL模板】二.创建表视图模板TSQL
    【SQL模板】一.修改/新增存储过程TSQL
    【转】Https内部机制基础知识
    【每日更新】【SQL实用大杂烩】
    expandableListview的默认箭头箭头怎样移到右边
    ExpandableListView的首次加载全部展开,并且点击Group不收缩、
    android 制作9.png图片
  • 原文地址:https://www.cnblogs.com/leiziv5/p/7257455.html
Copyright © 2011-2022 走看看