Skip to main content

Django rest recaptcha field for easy integration of google recaptcha with django-rest-framework.

Project description

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


#. Install with ``pip install django-rest-recaptcha``.

#. Add ``'recaptcha'`` to your ``INSTALLED_APPS`` setting.

#. 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:

.. code-block:: python

GR_CAPTCHA_SECRET_KEY = 'GoogleRecaptchaPrivateKey001'


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

.. code-block:: python

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.


.. code-block:: python

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.

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for django-rest-recaptcha, version 1.0.2
Filename, size File type Python version Upload date Hashes
Filename, size django_rest_recaptcha-1.0.2-py3-none-any.whl (3.7 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size django-rest-recaptcha-1.0.2.tar.gz (3.8 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page