Django recaptcha form field/widget app.
Project description
Django reCAPTCHA
Django reCAPTCHA form field/widget integration app.
django-recaptcha uses a modified version of the Python 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.
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. This can be seperately specified at runtime by passing a use_ssl parameter when constructing the ReCaptchaField, see field usage below.
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:
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.:
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 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.:
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 detects for DEBUG = True in the settings.py to facilitate unit tests. When DEBUG = TRUE, using PASSED as the recaptcha_response_field value.
Example:
form_params = {‘recaptcha_response_field’: ‘PASSED’} form = RegistrationForm(form_params) # assuming only one ReCaptchaField form.is_valid() # True
Passing any other values will cause django-recaptcha to continue normal processing and return a form error.
django-registration
django-recaptcha ships with a django-registration backend extending the default backend to include a reCAPTCHA field. This is included mostly as an example of how you could intergrate a reCAPTCHA field with django-registration. I suggest you familiarize yourself with the django-registration docs for more comprehensive documentation.
To use the reCAPTHCA backend complete these steps:
Add registration to your INSTALLED_APPS setting.
Add captcha registration backend url include to your project’s urls.py file:
(r'^accounts/', include('captcha.backends.default.urls')),
Add an ACCOUNT_ACTIVATION_DAYS setting to the project’s settings.py file. This is the number of days users will have to activate their accounts after registering, as required by django-registration, i.e.:
ACCOUNT_ACTIVATION_DAYS = 7
Implement the various templates as required by django-registration.
Once done you should be able to access /accounts/register/ and see the reCAPTCHA field in action as part of the registration process.
Credits
Inspired Marco Fucci’s blogpost titled Integrating reCAPTCHA with Django
client.py taken from recaptcha-client licenced MIT/X11 by Mike Crawford.
reCAPTCHA copyright 2011 Google.
Changelog
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
Built Distributions
File details
Details for the file django-recaptcha-0.0.4.tar.gz
.
File metadata
- Download URL: django-recaptcha-0.0.4.tar.gz
- Upload date:
- Size: 8.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 09c095129107068f588f3689e0130d63d1c8e35cfe1f4dadb1a8cbfd5bdb9602 |
|
MD5 | 9e28e8743d693610ab46096e888ada07 |
|
BLAKE2b-256 | bef78cff73509e8f4e636dc738470fa3c2182740dcaad439bd1f6520180ed6f3 |
Provenance
File details
Details for the file django_recaptcha-0.0.4-py2.7.egg
.
File metadata
- Download URL: django_recaptcha-0.0.4-py2.7.egg
- Upload date:
- Size: 15.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f23188df9bae91fb67de34194f4e733b374d3f2fe319edb55f1b9b3f921d9ee2 |
|
MD5 | 5be4937c4637c2a60ab436f8c2bb43ef |
|
BLAKE2b-256 | 5bc51ee96a3c5f0c95781828c0d76350523555e673884fab058e7dbb9489be80 |
Provenance
File details
Details for the file django_recaptcha-0.0.4-py2.6.egg
.
File metadata
- Download URL: django_recaptcha-0.0.4-py2.6.egg
- Upload date:
- Size: 15.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4ab437e40b1db7bacb2c5e8255344670f88c1b022440bbefb12f16bd044973a3 |
|
MD5 | 1eb5463b385e177f039a34ecf12ec10c |
|
BLAKE2b-256 | 3c40e9fc6b33cda3672f5f084a723c0989234c6074c61a957295acbf7115857f |