百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
F

flask-recaptcha

> 编程语言
开源

适用于 Flask 且不使用 Flask-WTF 的新 Google ReCaptcha 实现。

100 stars0 点赞0 次浏览
访问官网GitHub

工具介绍

适用于 Flask 且不使用 Flask-WTF 的新 Google ReCaptcha 实现。

Flask-ReCaptcha

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

Can also be used as standalone


Install

bash
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

    ... your field
    ... your field

    {{ recaptcha }}

    [submit button]

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_LANGUAGE: String - Language of the recaptcha texts. Defaults to 'en' (english). You can use fa (persian), ar (arabic), fr (french), etc.

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_LANGUAGE = "en"
RECAPTCHA_RTABINDEX = 10

(c) 2015 Mardix

Issues· 17 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

Python

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月18日
分类编程语言
定价开源

> 相关工具

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言