A Cloudflare Turnstile extension for Flask based on flask-recaptcha
Project description
Flask-Turnstile
A Cloudflare Turnstile extension for Flask based on flask-recaptcha.
Install
pip install flask-turnstile
Usage
Implementation view.py
from flask import Flask
from flask_turnstile import Turnstile
app = Flask(__name__)
turnstile = Turnstile(app=app)
#or
turnstile = Turnstile()
turnstile.init_app(app)
In your template: {{ turnstile }}
Inside of the form you want to protect, include the tag: {{ turnstile }}
It will insert the code automatically
<form method="post" action="/submit">
... your field
... your field
{{ turnstile }}
[submit button]
</form>
Verify the captcha
In the view that's going to validate the captcha
from flask import Flask
from flask_turnstile import Turnstile
app = Flask(__name__)
turnstile = Turnstile(app=app)
@route("/submit", methods=["POST"])
def submit():
if turnstile.verify():
# SUCCESS
pass
else:
# FAILED
pass
Api
turnstile.init(app, site_key, secret_key, is_enabled=True)
turnstile.get_code()
Returns the HTML code to implement. But you can use {{ turnstile }} directly in your template
turnstile.verfiy()
Returns bool
In Template
Just include {{ turnstile }} wherever you want to show the captcha
Config
Flask-Turnstile is configured through the standard Flask config API. These are the available options:
TURNSTILE_ENABLED: Bool - True by default, when False it will bypass validation
TURNSTILE_SITE_KEY : Public key
TURNSTILE_SECRET_KEY: Private key
The following are Optional arguments.
TURNSTILE_ENABLED = True
TURNSTILE_SITE_KEY = ""
TURNSTILE_SECRET_KEY = ""
(c) 2015 Mardix (c) 2023 Kristian
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
File details
Details for the file Flask-Turnstile-0.1.1.tar.gz
.
File metadata
- Download URL: Flask-Turnstile-0.1.1.tar.gz
- Upload date:
- Size: 4.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e97b51d684b59ffe1642eab92b3a8b75a57fd4cfc899baf1ee8eebffd9f05fbe |
|
MD5 | 1e482b303c952c9b218404478b38575b |
|
BLAKE2b-256 | 4750f7424b2d2e1257345a9e35801613ce1a57fa6ed75ba758110d5bb904b63a |
File details
Details for the file Flask_Turnstile-0.1.1-py3-none-any.whl
.
File metadata
- Download URL: Flask_Turnstile-0.1.1-py3-none-any.whl
- Upload date:
- Size: 4.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d5b97a5367489ac6368436e097e9e3b12645f39018f5d1747a9b58461384542b |
|
MD5 | a3968882299413fdc04420741a71385c |
|
BLAKE2b-256 | 505c4d8e2936a78625d905ced817d8fac0cc88d8f4cd43d32cf3bd77e9b63c8e |