Django recaptcha form field/widget app.
Project description
Django reCAPTCHA
================
**Django reCAPTCHA form field/widget integration app.**
.. image:: https://travis-ci.org/praekelt/django-recaptcha.svg?branch=develop
:target: https://travis-ci.org/praekelt/django-recaptcha
.. contents:: Contents
:depth: 5
django-recaptcha uses a modified version of the `Python reCAPTCHA client <http://pypi.python.org/pypi/recaptcha-client>`_ which is included in the package as ``client.py``.
Installation
------------
#. Install or add ``django-recaptcha`` to your Python path.
#. Add ``captcha`` to your ``INSTALLED_APPS`` setting.
#. Add a ``RECAPTCHA_PUBLIC_KEY`` setting to the project's ``settings.py`` file. This is your public API key as provided by reCAPTCHA, i.e.::
RECAPTCHA_PUBLIC_KEY = '76wtgdfsjhsydt7r5FFGFhgsdfytd656sad75fgh'
This can be seperately specified at runtime by passing a ``public_key`` parameter when constructing the ``ReCaptchaField``, see field usage below.
#. Add a ``RECAPTCHA_PRIVATE_KEY`` setting to the project's ``settings.py`` file. This is your private API key as provided by reCAPTCHA, i.e.::
RECAPTCHA_PRIVATE_KEY = '98dfg6df7g56df6gdfgdfg65JHJH656565GFGFGs'
This can be seperately specified at runtime by passing a ``private_key`` parameter when constructing the ``ReCaptchaField``, see field usage below.
#. If you would like to use the new No Captcha reCaptcha add a ``NOCAPTCHA = True`` setting to the project's ``settings.py`` file. ie.::
NOCAPTCHA = True
#. Optionally add a ``RECAPTCHA_USE_SSL`` setting to the project's ``settings.py`` file. This causes reCAPTCHA validation submits to be made over SSL, i.e.::
RECAPTCHA_USE_SSL = True
If you don't add this setting the default behaviour is to **NOT** use SSL. Note that if you have ``NOCAPTCHA = True`` set, SSL will always be used.
This can be seperately specified at runtime by passing a ``use_ssl`` parameter when constructing the ``ReCaptchaField``, see field usage below.
#. If you require a proxy, add a ``RECAPTCHA_PROXY`` setting to the project's ``settings.py`` file, i.e.::
RECAPTCHA_PROXY = 'http://127.0.0.1:8000'
Usage
-----
Field
~~~~~
The quickest way to add reCAPTHCA to a form is to use the included ``ReCaptchaField`` field type. A ``ReCaptcha`` widget will be rendered with the field validating itself without any further action required from you. For example:
.. code-block:: python
from django import forms
from captcha.fields import ReCaptchaField
class FormWithCaptcha(forms.Form):
captcha = ReCaptchaField()
To allow for runtime specification of keys and SSL usage you can optionally pass ``private_key``, ``public_key`` or ``use_ssl`` parameters to the constructor, i.e.:
.. code-block:: python
captcha = ReCaptchaField(
public_key='76wtgdfsjhsydt7r5FFGFhgsdfytd656sad75fgh',
private_key='98dfg6df7g56df6gdfgdfg65JHJH656565GFGFGs',
use_ssl=True
)
If specified these parameters will be used instead of your reCAPCTHA project settings.
The reCAPTCHA widget supports several `Javascript options variables <https://code.google.com/apis/recaptcha/docs/customization.html>`_ customizing the behaviour of the widget, such as ``theme`` and ``lang``. You can forward these options to the widget by passing an ``attr`` parameter containing a dictionary of options to ``ReCaptchaField``, i.e.:
.. code-block:: python
captcha = ReCaptchaField(attrs={'theme' : 'clean'})
The captcha client takes the key/value pairs and writes out the RecaptchaOptions value in JavaScript.
Unit Testing
~~~~~~~~~~~~
django-recaptcha introduces an environmental variable `RECAPTCHA_TESTING` which
helps facilitate tests. The environmental variable should be set to `"True"`,
and cleared, using the `setUp()` and `tearDown()` methods in your test classes.
Setting `RECAPTCHA_TESTING` to `True` causes django-recaptcha to accept
`"PASSED"` as the ``recaptcha_response_field`` value. Note that if you are using the new No Captcha reCaptcha
(ie. with ``NOCAPTCHA = True`` in your settings) the response field is called ``g-recaptcha-response``.
Example:
.. code-block:: python
import os
os.environ['RECAPTCHA_TESTING'] = 'True'
form_params = {'recaptcha_response_field': 'PASSED'} # use 'g-recaptcha-response' param name if using NOCAPTCHA
form = RegistrationForm(form_params) # assuming only one ReCaptchaField
form.is_valid() # True
os.environ['RECAPTCHA_TESTING'] = 'False'
form.is_valid() # False
Passing any other values will cause django-recaptcha to continue normal processing
and return a form error.
Check ``tests.py`` for a full example.
AJAX
~~~~~
To make Recapcha work in ajax-loaded forms:
#. import recaptcha_ajax.js on your page (not in the loaded template):
<script type="text/javascript" src="http://www.google.com/recaptcha/api/js/recaptcha_ajax.js"></script>
#. settings.py
CAPTCHA_AJAX = True
Credits
-------
Inspired Marco Fucci's blogpost titled `Integrating reCAPTCHA with Django <http://www.marcofucci.com/tumblelog/26/jul/2009/integrating-recaptcha-with-django>`_
``client.py`` taken from `recaptcha-client <http://pypi.python.org/pypi/recaptcha-client>`_ licenced MIT/X11 by Mike Crawford.
reCAPTCHA copyright 2012 Google.
.. |travis| image:: https://travis-ci.org/praekelt/device-recaptcha.png?branch=develop
.. _travis: https://travis-ci.org/praekelt/device-recaptcha
Authors
=======
Praekelt Foundation
-------------------
* Shaun Sephton
* Peter Pistorius
* Hedley Roos
bTaylor Design
--------------
* `Brandon Taylor <http://btaylordesign.com/>`_
Other
-----
* Brooks Travis
* `Denis Mishchishin <https://github.com/denz>`_
* `Joshua Peper <https://github.com/zout>`_
* `Rodrigo Primo <https://github.com/rodrigoprimo>`_
* `snnwolf <https://github.com/snnwolf>`_
* `Adriano Orioli <https://github.com/Aorioli>`_
* `cdvv7788 <https://github.com/cdvv7788>`_
* `Daniel Gatis Carrazzoni <https://github.com/danielgatis>`_
* `pbf <https://github.com/pbf>`_
* `Alexey Subbotin <https://github.com/dotsbb>`_
* `Sean Stewart <https://github.com/mindcruzer>`_
Changelog
=========
1.0.5 (2016-01-04)
------------------
#. Chinese translation (kz26).
#. Syntax fix (zvin).
#. Get tests to pass on Django 1.9.
1.0.4 (2015-04-16)
------------------
#. Fixed Python 3 support
#. Added Polish translations
#. Update docs
1.0.3 (2015-01-13)
------------------
#. Added nocaptcha recaptcha support
1.0.2 (2014-09-16)
------------------
#. Fixed Russian translations
#. Added Spanish translations
1.0.1 (2014-09-11)
------------------
#. Added Django 1.7 suport
#. Added Russian translations
#. Added multi dependancy support
#. Cleanup
1.0 (2014-04-23)
----------------
#. Added Python 3 support
#. Added French, Dutch and Brazilian Portuguese translations
0.0.9 (2014-02-14)
------------------
#. Bugfix: release master and not develop. This should fix the confusion due to master having been the default branch on Github.
0.0.8 (2014-02-13)
------------------
#. Bugfix: remove reference to options.html.
0.0.7 (2014-02-12)
------------------
#. Make it possible to load the widget via ajax.
0.0.6 (2013-01-31)
------------------
#. Added an extra parameter `lang` to bypass Google's language bug. See http://code.google.com/p/recaptcha/issues/detail?id=133#c3
#. widget.html no longer includes options.html. Options are added directly to widget.html
0.0.5 (2013-01-17)
------------------
#. Removed django-registration dependency
#. Changed testing mechanism to environmental variable `RECAPTCHA_TESTING`
0.0.4
-----
#. Handle missing REMOTE_ADDR request meta key. Thanks Joe Jasinski.
#. Added checks for settings.DEBUG to facilitate tests. Thanks Victor Neo.
#. Fix for correct iframe URL in case of no javascript. Thanks gerdemb.
0.0.3 (2011-09-20)
------------------
#. Don't force registration version thanks kshileev.
#. Render widget using template, thanks denz.
0.0.2 (2011-08-10)
------------------
#. Use remote IP when validating.
#. Added SSL support, thanks Brooks Travis.
#. Added support for Javascript reCAPTCHA widget options, thanks Brandon Taylor.
#. Allow for key and ssl specification at runtime, thanks Evgeny Fadeev.
0.0.1 (2010-06-17)
------------------
#. Initial release.
================
**Django reCAPTCHA form field/widget integration app.**
.. image:: https://travis-ci.org/praekelt/django-recaptcha.svg?branch=develop
:target: https://travis-ci.org/praekelt/django-recaptcha
.. contents:: Contents
:depth: 5
django-recaptcha uses a modified version of the `Python reCAPTCHA client <http://pypi.python.org/pypi/recaptcha-client>`_ which is included in the package as ``client.py``.
Installation
------------
#. Install or add ``django-recaptcha`` to your Python path.
#. Add ``captcha`` to your ``INSTALLED_APPS`` setting.
#. Add a ``RECAPTCHA_PUBLIC_KEY`` setting to the project's ``settings.py`` file. This is your public API key as provided by reCAPTCHA, i.e.::
RECAPTCHA_PUBLIC_KEY = '76wtgdfsjhsydt7r5FFGFhgsdfytd656sad75fgh'
This can be seperately specified at runtime by passing a ``public_key`` parameter when constructing the ``ReCaptchaField``, see field usage below.
#. Add a ``RECAPTCHA_PRIVATE_KEY`` setting to the project's ``settings.py`` file. This is your private API key as provided by reCAPTCHA, i.e.::
RECAPTCHA_PRIVATE_KEY = '98dfg6df7g56df6gdfgdfg65JHJH656565GFGFGs'
This can be seperately specified at runtime by passing a ``private_key`` parameter when constructing the ``ReCaptchaField``, see field usage below.
#. If you would like to use the new No Captcha reCaptcha add a ``NOCAPTCHA = True`` setting to the project's ``settings.py`` file. ie.::
NOCAPTCHA = True
#. Optionally add a ``RECAPTCHA_USE_SSL`` setting to the project's ``settings.py`` file. This causes reCAPTCHA validation submits to be made over SSL, i.e.::
RECAPTCHA_USE_SSL = True
If you don't add this setting the default behaviour is to **NOT** use SSL. Note that if you have ``NOCAPTCHA = True`` set, SSL will always be used.
This can be seperately specified at runtime by passing a ``use_ssl`` parameter when constructing the ``ReCaptchaField``, see field usage below.
#. If you require a proxy, add a ``RECAPTCHA_PROXY`` setting to the project's ``settings.py`` file, i.e.::
RECAPTCHA_PROXY = 'http://127.0.0.1:8000'
Usage
-----
Field
~~~~~
The quickest way to add reCAPTHCA to a form is to use the included ``ReCaptchaField`` field type. A ``ReCaptcha`` widget will be rendered with the field validating itself without any further action required from you. For example:
.. code-block:: python
from django import forms
from captcha.fields import ReCaptchaField
class FormWithCaptcha(forms.Form):
captcha = ReCaptchaField()
To allow for runtime specification of keys and SSL usage you can optionally pass ``private_key``, ``public_key`` or ``use_ssl`` parameters to the constructor, i.e.:
.. code-block:: python
captcha = ReCaptchaField(
public_key='76wtgdfsjhsydt7r5FFGFhgsdfytd656sad75fgh',
private_key='98dfg6df7g56df6gdfgdfg65JHJH656565GFGFGs',
use_ssl=True
)
If specified these parameters will be used instead of your reCAPCTHA project settings.
The reCAPTCHA widget supports several `Javascript options variables <https://code.google.com/apis/recaptcha/docs/customization.html>`_ customizing the behaviour of the widget, such as ``theme`` and ``lang``. You can forward these options to the widget by passing an ``attr`` parameter containing a dictionary of options to ``ReCaptchaField``, i.e.:
.. code-block:: python
captcha = ReCaptchaField(attrs={'theme' : 'clean'})
The captcha client takes the key/value pairs and writes out the RecaptchaOptions value in JavaScript.
Unit Testing
~~~~~~~~~~~~
django-recaptcha introduces an environmental variable `RECAPTCHA_TESTING` which
helps facilitate tests. The environmental variable should be set to `"True"`,
and cleared, using the `setUp()` and `tearDown()` methods in your test classes.
Setting `RECAPTCHA_TESTING` to `True` causes django-recaptcha to accept
`"PASSED"` as the ``recaptcha_response_field`` value. Note that if you are using the new No Captcha reCaptcha
(ie. with ``NOCAPTCHA = True`` in your settings) the response field is called ``g-recaptcha-response``.
Example:
.. code-block:: python
import os
os.environ['RECAPTCHA_TESTING'] = 'True'
form_params = {'recaptcha_response_field': 'PASSED'} # use 'g-recaptcha-response' param name if using NOCAPTCHA
form = RegistrationForm(form_params) # assuming only one ReCaptchaField
form.is_valid() # True
os.environ['RECAPTCHA_TESTING'] = 'False'
form.is_valid() # False
Passing any other values will cause django-recaptcha to continue normal processing
and return a form error.
Check ``tests.py`` for a full example.
AJAX
~~~~~
To make Recapcha work in ajax-loaded forms:
#. import recaptcha_ajax.js on your page (not in the loaded template):
<script type="text/javascript" src="http://www.google.com/recaptcha/api/js/recaptcha_ajax.js"></script>
#. settings.py
CAPTCHA_AJAX = True
Credits
-------
Inspired Marco Fucci's blogpost titled `Integrating reCAPTCHA with Django <http://www.marcofucci.com/tumblelog/26/jul/2009/integrating-recaptcha-with-django>`_
``client.py`` taken from `recaptcha-client <http://pypi.python.org/pypi/recaptcha-client>`_ licenced MIT/X11 by Mike Crawford.
reCAPTCHA copyright 2012 Google.
.. |travis| image:: https://travis-ci.org/praekelt/device-recaptcha.png?branch=develop
.. _travis: https://travis-ci.org/praekelt/device-recaptcha
Authors
=======
Praekelt Foundation
-------------------
* Shaun Sephton
* Peter Pistorius
* Hedley Roos
bTaylor Design
--------------
* `Brandon Taylor <http://btaylordesign.com/>`_
Other
-----
* Brooks Travis
* `Denis Mishchishin <https://github.com/denz>`_
* `Joshua Peper <https://github.com/zout>`_
* `Rodrigo Primo <https://github.com/rodrigoprimo>`_
* `snnwolf <https://github.com/snnwolf>`_
* `Adriano Orioli <https://github.com/Aorioli>`_
* `cdvv7788 <https://github.com/cdvv7788>`_
* `Daniel Gatis Carrazzoni <https://github.com/danielgatis>`_
* `pbf <https://github.com/pbf>`_
* `Alexey Subbotin <https://github.com/dotsbb>`_
* `Sean Stewart <https://github.com/mindcruzer>`_
Changelog
=========
1.0.5 (2016-01-04)
------------------
#. Chinese translation (kz26).
#. Syntax fix (zvin).
#. Get tests to pass on Django 1.9.
1.0.4 (2015-04-16)
------------------
#. Fixed Python 3 support
#. Added Polish translations
#. Update docs
1.0.3 (2015-01-13)
------------------
#. Added nocaptcha recaptcha support
1.0.2 (2014-09-16)
------------------
#. Fixed Russian translations
#. Added Spanish translations
1.0.1 (2014-09-11)
------------------
#. Added Django 1.7 suport
#. Added Russian translations
#. Added multi dependancy support
#. Cleanup
1.0 (2014-04-23)
----------------
#. Added Python 3 support
#. Added French, Dutch and Brazilian Portuguese translations
0.0.9 (2014-02-14)
------------------
#. Bugfix: release master and not develop. This should fix the confusion due to master having been the default branch on Github.
0.0.8 (2014-02-13)
------------------
#. Bugfix: remove reference to options.html.
0.0.7 (2014-02-12)
------------------
#. Make it possible to load the widget via ajax.
0.0.6 (2013-01-31)
------------------
#. Added an extra parameter `lang` to bypass Google's language bug. See http://code.google.com/p/recaptcha/issues/detail?id=133#c3
#. widget.html no longer includes options.html. Options are added directly to widget.html
0.0.5 (2013-01-17)
------------------
#. Removed django-registration dependency
#. Changed testing mechanism to environmental variable `RECAPTCHA_TESTING`
0.0.4
-----
#. Handle missing REMOTE_ADDR request meta key. Thanks Joe Jasinski.
#. Added checks for settings.DEBUG to facilitate tests. Thanks Victor Neo.
#. Fix for correct iframe URL in case of no javascript. Thanks gerdemb.
0.0.3 (2011-09-20)
------------------
#. Don't force registration version thanks kshileev.
#. Render widget using template, thanks denz.
0.0.2 (2011-08-10)
------------------
#. Use remote IP when validating.
#. Added SSL support, thanks Brooks Travis.
#. Added support for Javascript reCAPTCHA widget options, thanks Brandon Taylor.
#. Allow for key and ssl specification at runtime, thanks Evgeny Fadeev.
0.0.1 (2010-06-17)
------------------
#. Initial release.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
django-recaptcha-1.0.5.tar.gz
(12.6 kB
view details)
Built Distribution
django_recaptcha-1.0.5-py2.7.egg
(17.8 kB
view details)
File details
Details for the file django-recaptcha-1.0.5.tar.gz
.
File metadata
- Download URL: django-recaptcha-1.0.5.tar.gz
- Upload date:
- Size: 12.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | dc370fa0f7bd77378f8be5f03e88906bf0b62b8478b35af05846f7d640f1ec32 |
|
MD5 | 0314e33ebeda3405c2e22139954b3da4 |
|
BLAKE2b-256 | 8126e4e3a922f07a66ec78ab179691aa8f470a17c72f958678840546c0d3800a |
Provenance
File details
Details for the file django_recaptcha-1.0.5-py2.7.egg
.
File metadata
- Download URL: django_recaptcha-1.0.5-py2.7.egg
- Upload date:
- Size: 17.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d4d896dd399a1a0810af8e59a646bb5a1586b2cc8b8f32d16766ade5fba79475 |
|
MD5 | 2034a147d1386f70bc1229fc0785af87 |
|
BLAKE2b-256 | 77bb76524414044ff9941d2a6279554c575301654a5a06d2507467eed19c38e1 |