Custom WTForms field that handles reCaptcha display and validation
Project description
Overview
WTForms-reCaptcha is a convenient field for WTForms that transparently handles reCaptcha display and validation via corresponding widget and validator classes.
reCaptcha
Installation
Get the distribution:
pip install wtforms-recaptcha
or if you want the latest:
pip install hg+http://bitbucket.org/excieve/wtforms-recaptcha#egg=wtforms-recaptcha
or get hg clone of the source code:
hg clone http://bitbucket.org/excieve/wtforms-recaptcha cd wtforms-recaptcha python setup.py install
Usage
It is mostly the usual WTForms field that needs some extra data and parameters. Here’s a simple example:
from wtforms.form import Form from wtfrecaptcha.fields import RecaptchaField class CaptchaForm(Form): captcha = RecaptchaField(public_key=RECAPTCHA_PUB_KEY, private_key=RECAPTCHA_PRIV_KEY, secure=True) form = CaptchaForm(request.POST, captcha={'ip_address': request.META['REMOTE_ADDR']}) if form.validate(): print "Captcha response is correct" else: print form.errors['captcha']
Some description of field’s parameters:
- public_key:
Public key generated by reCaptcha service
- private_key:
Private key generated by reCaptcha service
- secure:
True if it should be served via HTTPS, False otherwise. Default: False.
When form with RecaptchaField is instantiated with bound fields, it must include captcha keyword parameter with dict that has ‘ip_address’ element.
Other details
Accessing field as a string will get the widget code with URLs that depend on secure parameter passed to the field.
HTTP errors and errors that are indepentent of user input are logged. Others are handled as validation errors.
License
See LICENCE for full licensing information.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file wtforms-recaptcha-0.1.0.tar.gz
.
File metadata
- Download URL: wtforms-recaptcha-0.1.0.tar.gz
- Upload date:
- Size: 6.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | cf5ea36403402383ba4fd1a38a8b876c11d1f4525d1fa3fd03d195b400b35046 |
|
MD5 | ff9c7c6b21b91440885700cc57c68271 |
|
BLAKE2b-256 | f48ab5effddee2228aa0c15d66ad161c9721f4f7dfe280ca569c20ccf80cde00 |