zoukankan      html  css  js  c++  java
  • 基于cookie实现用户验证

     1 #!/usr/bin/env python
     2 import tornado.ioloop
     3 import tornado.web
     4 
     5 class IndexHander(tornado.web.RequestHandler):
     6     def get(self, *args, **kwargs):
     7         if self.get_argument('u',None)in['alex','eric']:
     8             # self.set_cookie('name',self.get_argument('u'))
     9             self.write("登录成功")
    10             self.set_secure_cookie('user',self.get_argument('u'))
    11         else:
    12             self.write('请登录')
    13 class ManagerHandler(tornado.web.RequestHandler):
    14     def get(self, *args, **kwargs):
    15         # if self.get_cookie('name',None) in ['alex','eric']:
    16         if str(self.get_secure_cookie('user',None),encoding='utf-8') in ['alex','eric']:
    17             self.write("欢迎登录:" + str(self.get_secure_cookie('user'),encoding="utf-8"))
    18         else:
    19             self.redirect('/index')
    20 settings = {
    21     "template_path":"views",
    22     "static_path":"statics",
    23     "cookie_secret":"taochen"
    24 }
    25 
    26 application = tornado.web.Application([
    27     (r"/index",IndexHander),
    28     (r"/manager",ManagerHandler),
    29 ],**settings)
    30 
    31 if __name__ == '__main__':
    32     application.listen(8888)
    33     tornado.ioloop.IOLoop.instance().start()
  • 相关阅读:
    谷歌翻译python接口
    SRILM的安装方法
    语言模型srilm基本用法
    SRILM语言模型格式解读
    矩阵理解
    python生成器 协程
    python Queue模块使用
    scrapy 学习笔记2
    scrapy 学习笔记1
    xpath语法规则
  • 原文地址:https://www.cnblogs.com/shiluoliming/p/6558244.html
Copyright © 2011-2022 走看看