ReCaptcha in Django Forms
Using ReCaptcha widgets in forms managed by Django
ReCaptcha is a popular system for bot-blocking forms. The API allows integration of the ReCaptcha widget on our sites. In case of Python we can use recaptcha-client, which is used by a Django sippet adding form field for Django forms. In this article I'll show you simple example based on that snippet
- You have to start with making a set of keys for your domain
- Then you can add them to settings.py of your Django project:
- Install recaptcha-client through easy_install or other way
- Now we have to add the field and widget definition for Djang forms. It can be done like so - create a folder "recaptchawidget" in your project folder. Add 3 files in it: fields.py, widgets.py and __init__.py.
Now you can use ReCaptcha widgets in your forms. Here is an example form definition: And a view that manages the form: And the template: We are all done. The ReCaptcha widget will be validated as any other Django form field.