Skip to content
πŸ”’ Django rest recaptcha field for easy integration of google recaptcha with django-rest-framework.
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.
recaptcha Makes it testable May 25, 2018
README.rst Update version and license Aug 15, 2018


Django Rest reCAPTCHA

Django Rest reCAPTCHA field to add google recaptcha in django-rest-framework


Tested with:

  • Python: 2.7, 3.5
  • Django: 1.8, 1.9, 1.10, 1.11


  1. Install with pip install django-rest-recaptcha.
  2. Add 'recaptcha' to your INSTALLED_APPS setting.
  3. Register and obtain recaptcha keys here

#. Add the obtained keys to settings(For testing and development you can leave it blank to use default test keys as mentioned here For example:

GR_CAPTCHA_SECRET_KEY = 'GoogleRecaptchaPrivateKey001'


#. Now you can import and use the recaptcha field in your serializer. For example:

from rest_framework import serializers
from recaptcha.fields import ReCaptchaField

class ExampleSerializer(serializers.Serializer):
     recaptcha = ReCaptchaField(write_only=True)

Unit Testing

Django Rest reCAPTCHA uses an environment variable RECAPTCHA_TESTING which helps tests. This environment variable should be set to "True" in your testing environment and any value will be considered to be validated.


import os
os.environ['RECAPTCHA_TESTING'] = 'True'

data = {'recaptcha': 'dummy value'}
response ='/my/api/endpoint/', data)
assert response.status_code == 200

The code above may vary according to your testing suite.

You can’t perform that action at this time.