每天坐在教室里,但眼神总是看着窗外的风景,不知不觉的默默发呆。我一直急速前行,穿梭于人人之间。试图借应接不暇的风景让我褪去对你的思念。
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
haodaima.com<!DOCTYPE html>
haodaima.com<html>
haodaima.com<head>
haodaima.comhaodaima.com<title>reCaptcha验证码</title>
haodaima.com</head>
haodaima.com<body>
haodaima.comhaodaima.com<form action="" method="post">
haodaima.comhaodaima.com<script type="text/javascript" src="http://www.google.com/recaptcha/api/challenge?k={{ publickey }}"></script>
haodaima.comhaodaima.com<noscript>
haodaima.comhaodaima.comhaodaima.com<iframe src="http://www.google.com/recaptcha/api/noscript?k={{ publickey }}" height="300" width="500" frameborder="0"></iframe><br>
haodaima.comhaodaima.comhaodaima.com<textarea name="recaptcha_challenge_field" rows="3" cols="40"></textarea>
haodaima.comhaodaima.comhaodaima.com<input type="hidden" name="recaptcha_response_field" value="manual_challenge">
haodaima.comhaodaima.com</noscript>
haodaima.comhaodaima.com</form>
haodaima.com</body>
haodaima.com</html>
以上就是python为tornado添加recaptcha验证码功能。懂得应该怎样生活的人是高尚的,对此浑浑噩噩生活的人则完全可以说是不如奴隶的。省察自己的生活,保护好自己的心灵,去除造成生命痛苦的恶习、恶因,才会让自己成为如意生活的主人,才能摆脱奴隶一般被动受苦的人生。只有在省察中为自己而活,并找到合于真相、真理的良好意义,生活才会变得良好而清醒。更多关于python为tornado添加recaptcha验证码功能请关注haodaima.com其它相关文章!