Django REST hCAPTCHA v2 and v3 field serializer
- Python: 3.7, 3.8, 3.9, 3.10, 3.11
- Django: 3.2, 4.0, 4.1, 4.2
- DRF: 3.11, 3.12, 3.13, 3.14
- Install with
pip install drf-hcaptcha
- Add
"drf_hcaptcha"
to yourINSTALLED_APPS
settings. - Set in settings
DRF_HCAPTCHA_SECRET_KEY
INSTALLED_APPS = [
...,
"drf_hcaptcha",
...,
]
...
DRF_HCAPTCHA_SECRET_KEY = "YOUR SECRET KEY"
from rest_framework.serializers import Serializer
from drf_hcaptcha.fields import HCaptchaV2Field
class V2Serializer(Serializer):
hcaptcha = HCaptchaV2Field()
...
DRF_HCAPTCHA_SECRET_KEY
- set your hCAPTCHA secret key. Type: str.
DRF_HCAPTCHA_DEFAULT_V3_SCORE
- by default: 0.5
. Type: float.
DRF_HCAPTCHA_ACTION_V3_SCORES
- by default: {}
. Type: dict. You can define specific score for each action e.g. {"login": 0.6, "feedback": 0.3}
DRF_HCAPTCHA_DOMAIN
- by default: api.hcaptcha.com
. Type: str.
DRF_HCAPTCHA_PROXY
- by default: {}
. Type: dict. e.g. {'http': 'http://127.0.0.1:8000', 'https': 'https://127.0.0.1:8000'}
DRF_HCAPTCHA_VERIFY_REQUEST_TIMEOUT
- by default: 10
. Type: int.
- settings
DRF_HCAPTCHA_SECRET_KEY
- the argument
secret_key
of field - request.context["hcaptcha_secret_key"]
Validation is passed if the score value returned by Google is greater than or equal to required score.
Required score value: 0.0 - 1.0
If not defined or zero in current item then value from next item.
- Value for action in settings
DRF_HCAPTCHA_ACTION_V3_SCORES
- Value in argument
required_score
of field - Default value in settings
DRF_HCAPTCHA_DEFAULT_V3_SCORE
- Default value
0.5