Django reCaptcha v3 – Install reCaptcha in Django site

March 12th 2024 640 views • 1 comments

Django Recaptcha v3 will be installed in your Django website soon, just follow my instructions. We will be using Google Recaptcha version 3 ( I am not a robot ) and a Python library django-recaptcha for this task.

This is a repost of an old blog of ours.

How to install, deploy or integrate Django recaptcha v3?

Django recaptcha v3 installation

First, install django-recaptcha in your virtual workspace.

Visit the GitHub Repo of this task/project to get all the source codes.

Install and configure django-recaptcha lib

pip install django-recaptcha

Now, add captcha in the INSTALLED_APPS section in your


Must be similar to this:

    'captcha', # add this code

    "your_app_name", # app name

Recaptcha keys configuration

Add RECAPTCHA_PUBLIC_KEY and RECAPTCHA_PRIVATE_KEY at the last lines of your

RECAPTCHA_PUBLIC_KEY = 'MyRecaptchaKey123'
RECAPTCHA_PRIVATE_KEY = 'MyRecaptchaPrivateKey456'


Now, go to Google reCAPTCHA admin panel and register your site for reCAPTCHA and use those data in the upper code.

Cpatcha Form configuration

Now, create a file named and inside it you need to write the following Python codes:

from django import forms
from captcha.fields import ReCaptchaField

class FormWithCaptcha(forms.Form):
    captcha = ReCaptchaField()

Django views configuration

Write a context with "captcha" variable name that with render the form we have coded in FormWithCaptcha which is inside the .

from django.shortcuts import render
from .my_captcha import FormWithCaptcha
# Create your views here.
def home(request):
    context = {
        "captcha": FormWithCaptcha,
    return render(request, "home.html", context)

Rendering recaptcha v3

Now, we are rendering recaptcha using the Jinja template method. Use {{captcha}} for rendering the captcha form.

For now, have a look here:

<!DOCTYPE html>
<html lang="en">
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">


Getting data from recaptcha form

To get data from django recaptcha, you need to use g-recaptcha-response.

get_recaptcha = request.POST.get("g-recaptcha-response")

This will return true if the checkbox is checked, else false.