A hCaptcha extension for Flask based on flask-recaptcha
Project description
Flask-hCaptcha
A hCaptcha extension for Flask based on flask-recaptcha.
This repo is part of self-host video streaming project.
Install
pip install flask-hcaptcha
Usage
Implementation view.py
from flask import Flask
from flask_hcaptcha import hCaptcha
app = Flask(__name__)
hcaptcha = hCaptcha(app)
#or
hcaptcha = hCaptcha()
hcaptcha.init_app(app)
In your template: {{ hcaptcha }}
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>
Verify the captcha
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
Api
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
In Template
Just include {{ hcaptcha }} wherever you want to show the hcaptcha
Config
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)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for Flask_hCaptcha-0.5.4-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0a746e39af441caba58fa0c7622def8e66458ab707c3782a2673202bf6b55f59 |
|
MD5 | 7954d88408b798de7dce613471e9074f |
|
BLAKE2b-256 | 415cfb86281a49721326f36389de5e598b2f4d0b7aa1f9898267088bf9b84a26 |