Configure Recaptcha
Using Anvil Editor
Step 1 - Get recaptcha settings
Get your recaptcha key and secret from Google Recaptcha
Step 2 - Configure Frontend
- Modify
client_code
->script
->config.py
to put value of recaptcha key value in place of{recaptcha_client_key}
. - Modify 'Native Library' to replace
{recaptcha_client_key}
with the recaptcha key value.
Step 3 - Configure Server
- Open Secrets
- Put recaptcha secret as value for the defined secret
RECAPTCHA_SECRET
.
Using Python IDE
Step 1 - Get recaptcha settings
Get your recaptcha key and secret from Google Recaptcha
Step 2 - Configure Frontend
- Modify
client_code
->script
->config.py
to put value of recaptcha key value in place of{recaptcha_client_key}
. - Modify
anvil.yaml
to replace{recaptcha_client_key}
with the recaptcha key value.
Step 3 - Configure Server
- Open
settings
->config.yaml
and put value of secretRECAPTCHA_SECRET
as recaptcha secret.
Enable recaptcha for any server method call
from .recaptcha import ensure_recaptcha
@ensure_recaptcha
def server_action(param1, param2, recaptcha_token):
...
NOTE: For recaptcha enabled server methods, it´s mandatory to have a parameter with name recaptcha_token
.
Client side code changes for invoking recaptcha enabled server methods
from ..scripts.recaptcha import enforce_recaptcha
from anvil import server
@enforce_recaptcha
def continue_button_click(self, recaptcha_token, **event_args):
param1 = ...
param2 = ...
return server.call('server_action', param1, param2, recaptcha_token)
...