Replies: 8 comments
-
@shattie-kiene Did you get a workaround? I can't use it either. The validation always returns false. Related SO thread: https://stackoverflow.com/questions/62641672/django-form-validation-error-captcha-this-field-is-required |
Beta Was this translation helpful? Give feedback.
-
No, I didn’t find anything. This is clearly a bug in the code. I can advise you to use 'django-simple-captcha', if it’s not important for you to set recaptcha
|
Beta Was this translation helpful? Give feedback.
-
@shattie-kiene I actually don't want to use simple captcha, but it seems this lib isn't maintained anymore, so I will have to go for a different solution. Let's see. |
Beta Was this translation helpful? Give feedback.
-
You can do something like this in your tests
and mock the validate function so it doesn't raise an exception |
Beta Was this translation helpful? Give feedback.
-
@axil likely has the longterm solutution with the PR #216 #215 (comment) A work around from @qcaron is in: #157 (comment) also works with a small change. I am using the ReCaptchaV3 and had to set return to True if getattr(settings, "DEBUG", False):
captcha.clean = lambda x: True |
Beta Was this translation helpful? Give feedback.
-
This works, but does monkey-patching. A solution which uses mocking would be better, since mocks gets removed/reset, while monkey-patching changes the code for as long as the interpreter is running. |
Beta Was this translation helpful? Give feedback.
-
Sharing another take on the above workarounds for future ref: https://github.com/DjangoGirls/djangogirls/blob/0632a98bf198e3f3f427cb8f9f3334492feda167/core/forms.py#L11C1-L17C37 class BetterReCaptchaField(ReCaptchaField):
"""A ReCaptchaField that always works in DEBUG mode"""
def clean(self, values):
if settings.DEBUG:
return values[0]
return super().clean(values) |
Beta Was this translation helpful? Give feedback.
-
Re-reading this I’m not entirely sure whether there’s anything to change in the package here. The test/dev scenario is documented in the README. So I’ll convert to Discussions. Please add more information here or open a new issue if there’s a specific change / documentation improvement to make. |
Beta Was this translation helpful? Give feedback.
-
The problem is that when
RECAPTCHA_PUBLIC_KEY
andRECAPTCHA_PRIVATE_KEY
are removed, as well as whenSILENCED_SYSTEM_CHECKS = ['captcha.recaptcha_test_key_error']
is set, thecaptcha.fields.ReCaptchaField
generates an error "This field is required".Code
settings.py:
forms.py:
tests.py:
Beta Was this translation helpful? Give feedback.
All reactions