あなたは設定を試していませんが、あなたの再チャプタを動作させるためには、キーを指定する必要があります。これらの2つのオプションは、設定ではオプションではありません。
RECAPTCHA_SITE_KEY : Public key
RECAPTCHA_SECRET_KEY: Private key
適切な値で設定し、動作するかどうかを確認します。
EDIT:
それは今働いています。これはapp.pyです:
import requests
import json
from flask import Flask, render_template, request
from flask_recaptcha import ReCaptcha
app = Flask(__name__)
app.config.update({'RECAPTCHA_ENABLED': True,
'RECAPTCHA_SITE_KEY':
'site_key',
'RECAPTCHA_SECRET_KEY':
'secret_key'})
recaptcha = ReCaptcha(app=app)
@app.route('/')
def index():
return render_template('index.html')
@app.route('/submit', methods=['GET', 'POST'])
def submit():
print('SUBMIT CALLED')
username = ''
password = ''
if request.method == 'POST':
username = request.form['username']
password = request.form['password']
print(request.form)
if username == 'username' and password == 'password':
print('CREDENTIALS ARE OK')
r = requests.post('https://www.google.com/recaptcha/api/siteverify',
data = {'secret' :
'secret_key',
'response' :
request.form['g-recaptcha-response']})
google_response = json.loads(r.text)
print('JSON: ', google_response)
if google_response['success']:
print('SUCCESS')
return render_template('profile.html')
else:
# FAILED
print('FAILED')
return render_template('index.html')
# if recaptcha.verify():
# # SUCCESS
app.run(debug=True)
これはindex.htmlページです:あなたが検証に合格した場合
<!DOCTYPE html>
<html>
<head>
<script src='https://www.google.com/recaptcha/api.js'></script>
</head>
<body>
<h1>Flask Recaptcha</h1>
<p>Flask Recaptcha Test</p>
<form method="post" action="/submit">
Username:<br>
<input type="text" name="username"><br>
Password:<br>
<input type="password" name="password">
{{ recaptcha }}
<input type="submit" value="Submit">
<div class="g-recaptcha" data-sitekey="site_key"></div>
</form>
</body>
</html>
これはprofile.htmlページです:
私はcouldn
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<h1>Profile page</h1>
<p>Registration is ok</p>
</body>
</html>
recaptcha.verify()
を作ってください。 Google Recaptchaの公式ドキュメントでは、クライアントがあなたのsecret_key
とg-recaptcha-response
でフォームを送信した後に、recaptchaにチックを入れたときにGoogle recaptcha apiへの投稿リクエストを個別に送信する必要があることが記載されています。
これは単なるコード例です。 app.py
とindex.html
に独自のsite_keyとsecret_keyを追加する必要があります。また、パスワードを二重入力するなどの登録のためのユーザーの資格情報を適切に追加する必要があります。
コードが表示されていないと、ルートとテンプレートが含まれている可能性がありますか?また、拡張機能がまったく動作するためにはconfigが必要かもしれません。実際のコードを見ずに、再現する方法はありません。 – Maarten