Skip to main content

Easy Integration of Google Recaptcha in Flask

Project description

EasyFlaskRecaptcha

EasyFlaskRecaptcha is a python Module which makes Google Recaptcha Integration in flask application easy

Installation

pip install EasyFlaskRecaptcha

Implementation

from flask import Flask
from EasyFlaskRecaptcha import ReCaptcha

app = Flask(__name__)
recaptcha = ReCaptcha(app)

app.config.update(dict(
    GOOGLE_RECAPTCHA_ENABLED=True,
    GOOGLE_RECAPTCHA_SITE_KEY="6Lf74pUpXXXXXXXXXXXXXXXi012KXXXX7KB-31XXXH",
    GOOGLE_RECAPTCHA_SECRET_KEY="6LXXXXXXXXXXAFX-ZAXXXXXGSd-y5g0o-JZXXXXB"
))
recaptcha.init_app(app)

Flask Template Usage Example (Frontend)

Description: Use {{ recaptcha }} Tag inside form tag
<form method="post" action="/submit">
    ...
    {{ recaptcha }}

    [submit]
</form>

Flask Backend Route Example

@route("/submit", methods=["POST"])
def submit():
    if recaptcha.verify():
        print("SUCCESS") 
            
    else:
        print("FAILED")

Default Settings

GOOGLE_RECAPTCHA_ENABLED = True
GOOGLE_RECAPTCHA_THEME = "light"
GOOGLE_RECAPTCHA_TYPE = "image"
GOOGLE_RECAPTCHA_SIZE = "normal"
GOOGLE_RECAPTCHA_LANGUAGE = "en"
GOOGLE_RECAPTCHA_TABINDEX = 0

More Settings

GOOGLE_RECAPTCHA_ENABLED = True
GOOGLE_RECAPTCHA_SITE_KEY = ""
GOOGLE_RECAPTCHA_SECRET_KEY = ""
GOOGLE_RECAPTCHA_THEME = "light"
GOOGLE_RECAPTCHA_TYPE = "image"
GOOGLE_RECAPTCHA_SIZE = "normal"
GOOGLE_RECAPTCHA_LANGUAGE = "en"
GOOGLE_RECAPTCHA_TABINDEX = 10

Apply these settings like this:

from flask import Flask
from EasyFlaskRecaptcha import ReCaptcha

app = Flask(__name__)
recaptcha = ReCaptcha(app)

app.config.update(dict(
    GOOGLE_RECAPTCHA_ENABLED=True,
    GOOGLE_RECAPTCHA_SITE_KEY="6Lf74pUpXXXXXXXXXXXXXXXi012KXXXX7KB-31XXXH",
    GOOGLE_RECAPTCHA_SECRET_KEY="6LXXXXXXXXXXAFX-ZAXXXXXGSd-y5g0o-JZXXXXB",
    GOOGLE_RECAPTCHA_THEME = "light",
    GOOGLE_RECAPTCHA_TYPE = "image",
    GOOGLE_RECAPTCHA_SIZE = "normal",
    GOOGLE_RECAPTCHA_LANGUAGE = "en",
    GOOGLE_RECAPTCHA_RTABINDEX = 10,
))
recaptcha.init_app(app)
  • Figure out your desired language code (such as for english, language code is en) from this link: Google Recaptcha Language Codes
  • Set this parameter: GOOGLE_RECAPTCHA_LANGUAGE = "en"

Link:

License

This project is licensed under the MIT License (see the LICENSE file for details).

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

EasyFlaskRecaptcha-1.0.1-py3-none-any.whl (4.0 kB view details)

Uploaded Python 3

File details

Details for the file EasyFlaskRecaptcha-1.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for EasyFlaskRecaptcha-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 c95509bf6d705fa2d991889c45af9339bb1de093dd430d22cd1ec47c74c0f5f0
MD5 2308f6575c81dd8286fbf93ec7e8dc3e
BLAKE2b-256 fc116199714d91a6f9d7d6ec61ee9411a57bdfb159fa3562ea3bb68d40b558e5

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page