最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

python為tornado添加recaptcha驗證碼功能

 更新時間:2014年02月26日 14:08:18   作者:  
tornado作為微框架,并沒有自帶驗證碼組件,recaptcha是著名的驗證碼解決方案,簡單易用,被很多公司運用來防止惡意注冊和評論。tornado添加recaptchaHA非常容易

復制代碼 代碼如下:

    from urllib.request import urlopen
    from urllib.parse import urlencode
    import tornado.httpserver
    import tornado.ioloop
    import tornado.web

   
    #獲取key: https://www.google.com/recaptcha/whyrecaptcha
    publickey = '填入你的 public key'
    privatekey = '填入你的 private key'

   
    class Application(tornado.web.Application):
        def __init__(self):
            handlers = [
                (r'/', IndexHandler)
            ]
            settings = dict(
                template_path="templates",
            )

            tornado.web.Application.__init__(self, handlers, **settings)

   
    class IndexHandler(tornado.web.RequestHandler):
        def get(self):
            self.render('index.html', publickey=publickey)

        def post(self):
            url = 'http://www.google.com/recaptcha/api/verify'

            #驗證碼
            challenge = self.get_argument('recaptcha_challenge_field')
            #用戶輸入
            response = self.get_argument('recaptcha_response_field')

            data = {
                'privatekey': privatekey,
                'remoteip': self.request.remote_ip,
                'challenge': challenge,
                'response': response
            }

            res = urlopen(url, data=urlencode(data).encode())
            #獲取驗證結果,這里直接將返回結果輸出到頁面
            self.write(res.read().decode())

   
    if __name__ == '__main__':
        server = tornado.httpserver.HTTPServer(Application())
        server.listen(10001)
        tornado.ioloop.IOLoop.instance().start()
 
      

templates/index.html

復制代碼 代碼如下:
  
jb51.net<!DOCTYPE html>
jb51.net<html>
jb51.net<head>
jb51.netjb51.net<title>reCaptcha驗證碼</title>
jb51.net</head>
jb51.net<body>
jb51.netjb51.net<form action="" method="post">
jb51.netjb51.net<script type="text/javascript" src="http://www.google.com/recaptcha/api/challenge?k={{ publickey }}"></script>
jb51.netjb51.net<noscript>
jb51.netjb51.netjb51.net<iframe src="http://www.google.com/recaptcha/api/noscript?k={{ publickey }}" height="300" width="500" frameborder="0"></iframe><br>
jb51.netjb51.netjb51.net<textarea name="recaptcha_challenge_field" rows="3" cols="40"></textarea>
jb51.netjb51.netjb51.net<input type="hidden" name="recaptcha_response_field" value="manual_challenge">
jb51.netjb51.net</noscript>
jb51.netjb51.net</form>
jb51.net</body>
jb51.net</html>

相關文章

最新評論

蒲江县| 共和县| 望城县| 长武县| 许昌市| 湖南省| 威远县| 小金县| 兴仁县| 巩留县| 温宿县| 宜川县| 秀山| 和硕县| 牙克石市| 郴州市| 普定县| 鹤壁市| 贵溪市| 大埔区| 涿州市| 托克逊县| 离岛区| 德江县| 巨野县| 南昌县| 呼伦贝尔市| 蒙阴县| 靖宇县| 临江市| 丹寨县| 高淳县| 九龙坡区| 县级市| 怀仁县| 吉隆县| 莲花县| 奇台县| 海安县| 新丰县| 元江|