zoukankan      html  css  js  c++  java
  • tornado 作业 简单首页 登录页 个人中心

    s4 index.py

     1 import tornado.ioloop
     2 import tornado.web
     3 import time
     4 
     5 
     6 class IndexHandler(tornado.web.RequestHandler):
     7     def get(self,*args,**kwargs):
     8         self.render('index.html')
     9 
    10 class LogoutHandle(tornado.web.RequestHandler):
    11     def get(self,*args,**kwargs):
    12         self.set_cookie('auth','0')
    13         self.redirect('/login')
    14 
    15 class ManagerHandler(tornado.web.RequestHandler):
    16     def get(self,*args,**kwargs):
    17         co=self.get_cookie('auth')
    18         if co == '1':
    19             self.render('manager.html')
    20         else:
    21             self.redirect('/login')
    22 
    23 class LoginHandler(tornado.web.RequestHandler):
    24     def get(self,*args,**kwargs):
    25         self.render('login.html',Logon_failure='')
    26     def post(self, *args, **kwargs):
    27         username=self.get_argument('username',None)
    28         pwd = self.get_argument('password', None)
    29         chexk=self.get_argument('auto',None)
    30         if username=='alex' and pwd=='sb':
    31             if chexk==1:
    32                 self.set_cookie('auth', '1', expires_days=7)
    33             r=time.time()+100
    34             self.set_cookie('auth','1',expires=r)
    35             self.redirect('/manager')
    36         else:
    37             self.render('login.html',Logon_failure="登陆失败")
    38 settings={
    39     'template_path':'tpl',
    40     'static_path': 'static',
    41 }
    42 application = tornado.web.Application([
    43     (r"/index", IndexHandler),
    44     (r"/manager", ManagerHandler),
    45     (r"/login", LoginHandler),
    46     (r"/logout", LogoutHandle),
    47 ],**settings)
    48 
    49 if __name__ == "__main__":
    50     application.listen(8888)
    51     tornado.ioloop.IOLoop.instance().start()
    View Code

    manager.html

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Title</title>
    </head>
    <body>
    <a href="/logout">退出</a>
    <h1>银行卡余额:-1000</h1>
    </body>
    </html>

    login.html

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Title</title>
    </head>
    <body>
    <form action="/login" method="post">
        <input type="text" name="username">
        <input type="password" name="password">
        <input type="submit" value="登录">
        <input type="checkbox" name="auto" value="1">七天面登录
        <span>{{Logon_failure}}</span>
    </form>
    </body>
    </html>

    index.html

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Title</title>
    </head>
    <body>
    <h1>首页</h1>
    </body>
    </html>
  • 相关阅读:
    HDU3145 Max Sum of Max-K-sub-sequence (单调队列模板)
    AcWing1088 旅行问题(单调队列)
    POJ1821 Fence(单调队列)
    POJ1742 Coins(多重背包+二进制优化)
    AcWing217 绿豆蛙的归宿(期望)
    BZOJ.2134.[国家集训队]单选错位(概率 递推)
    洛谷.3805.[模板]manacher算法
    Codeforces.280C.Game on Tree(期望)
    BZOJ.2521.[SHOI2010]最小生成树(最小割ISAP/Dinic)
    洛谷.4172.[WC2006]水管局长(LCT Kruskal)
  • 原文地址:https://www.cnblogs.com/koushuige/p/8312918.html
Copyright © 2011-2022 走看看