I have been trying to use the Google reCAPTCHA on a website that I've been making. The captcha loads on the webpage but I've been unable to validate it using several methods. I've tried the recaptcha validation using the method given at How to use Python plugin reCaptcha client for validation? but I think it's outdated as it no longer works and it is referring to challenges whereas the one I'm trying to use is the new 'checkbox' reCAPTCHA v2 by Google or maybe I need to make changes in my settings after installing recaptcha-client or django-recaptcha.
Please help!
Here is a simple example to verify Google reCAPTCHA v2 within Django view using
requests
library (http://docs.python-requests.org/en/latest/):There is a third-party Django app to implement the new reCAPTCHA v2 here:
https://github.com/ImaginaryLandscape/django-nocaptcha-recaptcha
After installing it, add the following lines to the following files:
Google has changed the API around, we need to use a POST request now. Here a re-usable solution in case you need to do the validation in more than one django view:
utils.py
then:
views.py
Note we are using django-ipware in this solution to get the ip address, but this is up to you. Also, don't forget to add
GOOGLE_VERIFY_RECAPTCHA_URL
andRECAPTCHA_SECRET_KEY
to the django settings file!