A hCaptcha extension for Flask based on flask-recaptcha.
pip install flask-hcaptcha
from flask import Flask
from flask_hcaptcha import hCaptcha
app = Flask(__name__)
hcaptcha = hCaptcha(app)
#or
hcaptcha = hCaptcha()
hcaptcha.init_app(app)
Inside of the form you want to protect, include the tag: {{ hcaptcha }}
It will insert the code automatically
<form method="post" action="/submit">
... your field
... your field
{{ hcaptcha }}
[submit button]
</form>
In the view that's going to validate the captcha
from flask import Flask
from flask_hcaptcha import hCaptcha
app = Flask(__name__)
hcaptcha = hCaptcha(app)
@route("/submit", methods=["POST"])
def submit():
if hcaptcha.verify():
# SUCCESS
pass
else:
# FAILED
pass
hCaptcha.init(app, site_key, secret_key, is_enabled=True)
hCaptcha.get_code()
Returns the HTML code to implement. But you can use {{ hcaptcha }} directly in your template
hCaptcha.verfiy()
Returns bool
Just include {{ hcaptcha }} wherever you want to show the hcaptcha
Flask-ReCaptcha is configured through the standard Flask config API. These are the available options:
HCAPTCHA_ENABLED: Bool - True by default, when False it will bypass validation
HCAPTCHA_SITE_KEY : Public key
HCAPTCHA_SECRET_KEY: Private key
RECAPTCHA_ENABLED = True
RECAPTCHA_SITE_KEY = ""
RECAPTCHA_SECRET_KEY = ""
(c) 2020 Knugi (originally ReCaptcha by Mardix 2015)