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

python為tornado添加recaptcha驗(yàn)證碼功能

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

復(fù)制代碼 代碼如下:

    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'

            #驗(yàn)證碼
            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())
            #獲取驗(yàn)證結(jié)果,這里直接將返回結(jié)果輸出到頁面
            self.write(res.read().decode())

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

templates/index.html

復(fù)制代碼 代碼如下:
  
jb51.net<!DOCTYPE html>
jb51.net<html>
jb51.net<head>
jb51.netjb51.net<title>reCaptcha驗(yàn)證碼</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>

相關(guān)文章

最新評(píng)論

永仁县| 杂多县| 江北区| 治多县| 洛阳市| 曲阳县| 内黄县| 景谷| 卓尼县| 沙洋县| 伊川县| 延川县| 台山市| 交城县| 柘荣县| 壤塘县| 墨玉县| 攀枝花市| 慈溪市| 永州市| 离岛区| 永清县| 苍南县| 湖口县| 济宁市| 清水河县| 乳山市| 五莲县| 郯城县| 沂水县| 洪泽县| 镇江市| 肥西县| 开化县| 白山市| 靖宇县| 克东县| 宜兰市| 石门县| 金坛市| 松原市|