SmileyChris

Recaptcha

Rambling on about Django 89 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 (48)

:) Chris said: (89 months ago)

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

You seeing this? Good.

:) Chris said: (89 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: (88 months ago)

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

chrome said: (88 months ago)

Reading is fundamental! Thanks for posting this.

itsnotvalid said: (88 months ago)

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

:) Chris said: (88 months ago)

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

Just testing said: (88 months ago)

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

buriy said: (88 months ago)

Please put it on recaptcha now ;)

Curious said: (87 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: (87 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: (87 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: (86 months ago)

way cool!!

johnn said: (86 months ago)

Great tool man! seriusly awesome!

johnny said: (86 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: (85 months ago)

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

macdet said: (84 months ago)

yes, great!

I`ll came back and read more.

Al said: (82 months ago)

Quick test

humaun said: (80 months ago)

I know data entry.

ankara nakliyat said: (76 months ago)

very nice article.

denz said: (74 months ago)

thanks man!

lhv said: (74 months ago)

Sorry, just testing

Nathaniel Tucker said: (74 months ago)

Put this up on google code?

:) Chris said: (74 months ago)

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

test said: (67 months ago)

test

test said: (65 months ago)

test

test said: (65 months ago)

test more

J said: (64 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: (58 months ago)

test

test said: (58 months ago)

test

velda said: (52 months ago)

Hey there, hope you don't mind me using your form to test :) I've got someone else saying I'm not a human, consistently, so I thought I'd check someone eles's form to see if their recaptcha works.. and you were up there in google. ;) Thanks, and feel free to delete this.

velda said: (52 months ago)

Oh and I'd say your blog is read :) Good luck with it.

:) Chris said: (52 months ago)

Thanks, velda. I haven't blogged in forever and have considered just shutting it down - it's good to know some people still look for it.

I'll give myself a challenge of writing at least something each month for the next 6 - it shouldn't be that difficult really... :P

test said: (50 months ago)

test

just testing said: (50 months ago)

testing 123

test said: (42 months ago)

test

hehhe said: (41 months ago)

:) testing something here

hehhe said: (41 months ago)

its a captcha bug

hehhe said: (41 months ago)

that you may skip a word of it. not really bug though

hello said: (39 months ago)

bye

Leissa Schriever said: (36 months ago)

Lord Inglip be praised.

Jg said: (35 months ago)

Hj

Jggydfh said: (35 months ago)

Recaptcha sucks and i can pwn it

herp said: (34 months ago)

Testing

testing said: (33 months ago)

Hi

hi said: (13 months ago)

dfasfd

test said: (7 months ago)

hi

aaoisd said: (5 months ago)

niiiiceee

noasin said: (5 months ago)

n11c3

Leave a comment