SmileyChris

Recaptcha

Rambling on about Django 33 months ago.

So, trawling Digg today I came across Recaptcha - a neat site which not only offers you CAPTCHA generation and validation, but takes the words from scanned books so that users are actually helping digitise books while they validate that they are indeed human!

So, since I was told that I "really should have comments" on my blog which nobody reads, I thought it would be a good exercise to implement this in Django using the soon-to-be-standard newforms.

If you're a Django-ite, you may be interested to see the code of this module (feel free to use it).

Since I'm too lazy to document, here's my forms.py code:

class CommentForm(RecaptchaForm):
    name = CharField()
    comment = CharField(widget=Textarea(attrs={'class': 'wide'}))
    website = URLField(widget=TextInput(attrs={'class': 'wide'}),
                       label='Web site (optional)',
                       required=False)
    captcha = RecaptchaFieldPlaceholder(widget=RecaptchaWidget(theme='white'),
                                        label='Are you a human?')

(We use RecaptchaFieldPlaceholder because the real RecaptchaField needs to be initialised with the remote_ip)

In your view, initialise the form as per usual, but pass the remote_ip as the first argument:

remote_ip = request.META['REMOTE_ADDR']
form = CommentForm(remote_ip, data)

Update (30 August 2007): file updated to work with a backwards incompatible change in SVN trunk

Leave a comment or see my other ramblings.

Comments (29)

:) Chris said: (33 months ago)

I guess I better make sure comments are actually working on the live site.

You seeing this? Good.

:) Chris said: (33 months ago)

For niceness on this blog, that if you prove you're a human then you don't need to prove it again for two weeks (in case of nanite infections)

bram said: (33 months ago)

just a test to see if it's working :-) nice going Chris!

chrome said: (33 months ago)

Reading is fundamental! Thanks for posting this.

itsnotvalid said: (33 months ago)

I think you should submit this code to reCAPTCHA project to add to their plugin download page.

:) Chris said: (33 months ago)

Probably a good idea, however I'll wait to get some feedback on the code first.

Just testing said: (33 months ago)

I'm currious so I want to test this reCAPTCHA thing.
Sorry for the noise...

buriy said: (32 months ago)

Please put it on recaptcha now ;)

Curious said: (31 months ago)

Just wanted to see if this was any good.

Kind of a disappointment that I can't see the original scanned words, it'd be nice to be able to be the guy that solves an unreadable word, rather than just typing the same incorrectly read word that everyone else has to type.

Curious said: (31 months ago)

Isn't there a way to hide the comment box used for the returned code until I have clicked the "I'm a human" button?

I wasn't sure what I was meant to do with the box before I had typed the captchas in.

:) Chris said: (31 months ago)

Hi Curious,

Yup, I could have made the process different - I thought it was a bit easier for people to type it in as part of the comment step though. Perhaps my wording could be clearer on what you are meant to do rather than making an ass out of you and umption.

syd said: (31 months ago)

way cool!!

johnn said: (31 months ago)

Great tool man! seriusly awesome!

johnny said: (31 months ago)

well, the audible captcha is a bit clunky, but well, I guess there are some voice recognition softares arond. great captchas, I'm probably going to use this! thanks!

Jeff said: (30 months ago)

This is great, exactly what I was looking for, thanks!

macdet said: (29 months ago)

yes, great!

I`ll came back and read more.

Al said: (27 months ago)

Quick test

humaun said: (25 months ago)

I know data entry.

ankara nakliyat said: (21 months ago)

very nice article.

denz said: (18 months ago)

thanks man!

lhv said: (18 months ago)

Sorry, just testing

Nathaniel Tucker said: (18 months ago)

Put this up on google code?

:) Chris said: (18 months ago)

Guess I could... but it's pretty simple. Not sure it really needs a whole project.

test said: (12 months ago)

test

test said: (10 months ago)

test

test said: (10 months ago)

test more

J said: (9 months ago)

The audio returned is whatever!

The visual words:
Enduring day

Audio:
"The opera? I don't know a thing about shakespeare"

test said: (12 weeks ago)

test

test said: (12 weeks ago)

test

Leave a comment