diff --git a/docs/config.rst b/docs/config.rst index b4decaed..20a0daa7 100644 --- a/docs/config.rst +++ b/docs/config.rst @@ -37,6 +37,8 @@ Recaptcha ``RECAPTCHA_PUBLIC_KEY`` **required** A public key. ``RECAPTCHA_PRIVATE_KEY`` **required** A private key. https://www.google.com/recaptcha/admin +``RECAPTCHA_DISABLE`` Disable recaptcha widgets. + Default is ``False`` ``RECAPTCHA_PARAMETERS`` **optional** A dict of configuration options. ``RECAPTCHA_HTML`` **optional** Override default HTML template for Recaptcha. diff --git a/docs/form.rst b/docs/form.rst index 69fb79f1..b9e195cf 100644 --- a/docs/form.rst +++ b/docs/form.rst @@ -142,6 +142,11 @@ Example of RECAPTCHA_PARAMETERS, and RECAPTCHA_DATA_ATTRS:: For your convenience, when testing your application, if ``app.testing`` is ``True``, the recaptcha field will always be valid. +In development environment or when you are offline you can disable all +recaptcha fields:: + + RECAPTCHA_DISABLE = True + And it can be easily setup in the templates: .. sourcecode:: html+jinja diff --git a/src/flask_wtf/recaptcha/validators.py b/src/flask_wtf/recaptcha/validators.py index 10712d9c..ed248157 100644 --- a/src/flask_wtf/recaptcha/validators.py +++ b/src/flask_wtf/recaptcha/validators.py @@ -27,7 +27,7 @@ def __init__(self, message=None): self.message = message def __call__(self, form, field): - if current_app.testing: + if current_app.testing or current_app.config.get("RECAPTCHA_DISABLE", False): return True if request.json: diff --git a/src/flask_wtf/recaptcha/widgets.py b/src/flask_wtf/recaptcha/widgets.py index 7dc65071..be2530be 100644 --- a/src/flask_wtf/recaptcha/widgets.py +++ b/src/flask_wtf/recaptcha/widgets.py @@ -37,6 +37,9 @@ def recaptcha_html(self, public_key): def __call__(self, field, error=None, **kwargs): """Returns the recaptcha input HTML.""" + if current_app.config.get("RECAPTCHA_DISABLE", False): + return Markup("") + try: public_key = current_app.config["RECAPTCHA_PUBLIC_KEY"] except KeyError: