Giter VIP home page Giter VIP logo

flask-recaptcha's Introduction

Flask-ReCaptcha

The new Google ReCaptcha implementation for Flask without Flask-WTF.

Can also be used as standalone


Install

pip install flask-recaptcha

Usage

Implementation view.py

from flask import Flask
from flask_recaptcha import ReCaptcha

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

#or 

recaptcha = Recaptcha()
recaptcha.init_app(app)

In your template: {{ recaptcha }}

Inside of the form you want to protect, include the tag: {{ recaptcha }}

It will insert the code automatically If using Invisible reCAPTCHA

... your field ... your field

    {{ recaptcha(my-form, onSubmitCallback) }}

    [submit button]
</form>

If using reCAPTCHA ... your field ... your field

    {{ recaptcha() }}

    [submit button]
</form>

Verify the captcha

In the view that's going to validate the captcha

from flask import Flask
from flask_recaptcha import ReCaptcha

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

@route("/submit", methods=["POST"])
def submit():

    if recaptcha.verify():
        # SUCCESS
        pass
    else:
        # FAILED
        pass

Api

reCaptcha.init(app, site_key, secret_key, is_enabled=True)

reCaptcha.get_code()

Returns the HTML code to implement. But you can use {{ recaptcha }} directly in your template

reCaptcha.verfiy()

Returns bool

In Template

Just include {{ recaptcha() }} wherever you want to show the recaptcha

Config

Flask-ReCaptcha is configured through the standard Flask config API. These are the available options:

RECAPTCHA_ENABLED: Bool - True by default, when False it will bypass validation

RECAPTCHA_SITE_KEY : Public key

RECAPTCHA_SECRET_KEY: Private key

The following are Optional arguments.

RECAPTCHA_THEME: String - Theme can be 'light'(default) or 'dark'

RECAPTCHA_TYPE: String - Type of recaptcha can be 'image'(default) or 'audio'

RECAPTCHA_SIZE: String - Size of the image can be 'normal'(default) or 'compact'

RECAPTCHA_TABINDEX: Int - Tabindex of the widget can be used, if the page uses tabidex, to make navigation easier. Defaults to 0

RECAPTCHA_ENABLED = True
RECAPTCHA_SITE_KEY = ""
RECAPTCHA_SECRET_KEY = ""
RECAPTCHA_THEME = "dark"
RECAPTCHA_TYPE = "image"
RECAPTCHA_SIZE = "compact"
RECAPTCHA_RTABINDEX = 10

(c) 2015 Mardix

flask-recaptcha's People

Contributors

mardix avatar nobane avatar wanderingstan avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

Forkers

mygirl8893

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.