Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/justquick/django-math-captcha
A simple, secure way to add easy math questions to Django forms for captcha
https://github.com/justquick/django-math-captcha
Last synced: 3 months ago
JSON representation
A simple, secure way to add easy math questions to Django forms for captcha
- Host: GitHub
- URL: https://github.com/justquick/django-math-captcha
- Owner: justquick
- Created: 2009-11-12T04:26:08.000Z (about 15 years ago)
- Default Branch: master
- Last Pushed: 2015-06-15T07:55:37.000Z (over 9 years ago)
- Last Synced: 2024-10-02T22:04:56.724Z (4 months ago)
- Language: Python
- Homepage:
- Size: 123 KB
- Stars: 24
- Watchers: 5
- Forks: 9
- Open Issues: 3
-
Metadata Files:
- Readme: README.rst
Awesome Lists containing this project
README
Simple Math Captcha
=========================:Authors:
Justin Quick
:Version: 0.1Django Math Captcha is an easy way to add mathematical captcha verification to your already existing forms.
It asks you a simple math question (eg ``'1 + 2 ='``) and validates the form if your response is correct.
All you have to do is subclass either ``MathCaptchaForm`` or ``MathCaptchaModelForm`` in your own forms.Extending your forms::
from math_captcha import MathCaptchaModelForm
from myapp.forms import BlogFormclass MyExistingForm(BlogForm,MathCaptchaModelForm): # instead of forms.ModelForm
#... extra fields here
Now you can be certain that the only users who create blogs are humans.
Check out the example project for more practical use and tests.
Using with other apps
----------------------If you are running an app like, say `django-contact-form`_ and want to add math captcha here is how to go about it.
Add the following in your ``urls.py``::
from contact_form.forms import ContactForm
from math_captcha.forms import MathCaptchaForm
class CaptchaContactForm(ContactForm,MathCaptchaForm):
pass
urlpatterns = patterns('',
...
url(r'^contact/$','contact_form.views.contact_form',{'form_class':CaptchaContactForm},name='contact_form'),
url(r'^contact/sent/$','django.views.generic.simple.direct_to_template',{ 'template': 'contact_form/contact_form_sent.html' },name='contact_form_sent'),
...
)
Now the contact form will block robots who cant do math... _django-contact-form: http://bitbucket.org/ubernostrum/django-contact-form
Settings
---------Set the behavior of the math captcha interaction in your ``settings.py``
``MATH_CAPTCHA_NUMBERS = (1,2,3,4,5)``
A list of numbers to randomly choose from when generating the questions.
Defaults to 1 through 5.``MATH_CAPTCHA_OPERATORS = '+-'``
String containing mathematical operators to use. Default is only add (``+``) and subtract (``-``).
Available operators are: add (``+``), subtract (``-``), multiply (``*``), divide (``/``), and modulo (``%``)``MATH_CAPTCHA_QUESTION = 'Are you human?'``
Question that appears on forms as a label for math questions. By default it is ``'Are you human?'``