Implementing reCAPTCHA v2 after Simple Captcha
This article details the steps you need to take in order to modify your existing Captcha to reCAPTCHA.
Simple forms of Captcha are easily defeated by robots, so this is an essential step to beef up your spam protection.

Kalle Tolonen · · 4 min read
Requirements
- A working django-simple-captcha implementation
- Being comfortable with Django & Python
Tested on Debian 11 & Apache2
Register your site @ Google reCAPTCHA
Go to https://www.google.com/recaptcha/admin/create.

127.0.0.1 is localhost, so that’s good for development. After you’re done with the registration, you need to add your keys (that you get after submitting the form) to settings.py.
#settings.py
RECAPTCHA_PUBLIC_KEY = 'site key goes here'
RECAPTCHA_PRIVATE_KEY = 'secret key goes here'While you’re at settings, remove all references to django-simple-captcha.
Modifying requirements
Modify your requirements.txt and replace django-simple-captcha pkg with django-recaptcha.
#requirements.txt
django-recaptcha
Next, let’s Uninstall django-simple-captcha and install the altered requirements.
pip uninstall django-simple-captcha
pip install -r requirements.txt
Check settings.py
Make sure you still have ‘captcha’ in your apps.
After that you should run migrations just to be sure.
,/manage.py makemigrations
./manage.py migrate
Forms
To use this, you need to modify your form fields.
#forms.py
from django import forms
from captcha.fields import ReCaptchaField
from captcha.widgets import ReCaptchaV2Checkbox
class ContactForm(forms.Form):
name = forms.CharField(max_length = 50)
email = forms.EmailField(max_length = 150)
message = forms.CharField(widget = forms.Textarea, max_length = 2000)
captcha = ReCaptchaField(widget=ReCaptchaV2Checkbox)Views & Templates
You don’t need to modify views or templates if you’ve been using django-simple-captcha - you can check those out here.
Sources
https://www.geeksforgeeks.org/how-to-add-google-recaptcha-to-django-forms/
Comments
No published comments yet.
Add a Comment
Your comment is held for review before it appears publicly.