Rambling on about Django 99 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 code:

class CommentForm(RecaptchaForm):
    name = CharField()
    comment = CharField(widget=Textarea(attrs={'class': 'wide'}))
    website = URLField(widget=TextInput(attrs={'class': 'wide'}),
                       label='Web site (optional)',
    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: (99 months ago)

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

You seeing this? Good.

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

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

chrome said: (99 months ago)

Reading is fundamental! Thanks for posting this.

itsnotvalid said: (99 months ago)

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

:) Chris said: (99 months ago)

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

Just testing said: (99 months ago)

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

buriy said: (98 months ago)

Please put it on recaptcha now ;)

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

way cool!!

johnn said: (96 months ago)

Great tool man! seriusly awesome!

johnny said: (96 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: (95 months ago)

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

macdet said: (95 months ago)

yes, great!

I`ll came back and read more.

Al said: (93 months ago)

Quick test

humaun said: (91 months ago)

I know data entry.

ankara nakliyat said: (87 months ago)

very nice article.

denz said: (84 months ago)

thanks man!

lhv said: (84 months ago)

Sorry, just testing

Nathaniel Tucker said: (84 months ago)

Put this up on google code?

:) Chris said: (84 months ago)

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

test said: (78 months ago)


test said: (75 months ago)


test said: (75 months ago)

test more

J said: (74 months ago)

The audio returned is whatever!

The visual words:
Enduring day

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

test said: (68 months ago)


test said: (68 months ago)


velda said: (62 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: (62 months ago)

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

:) Chris said: (62 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: (61 months ago)


just testing said: (61 months ago)

testing 123

test said: (52 months ago)


hehhe said: (51 months ago)

:) testing something here

hehhe said: (51 months ago)

its a captcha bug

hehhe said: (51 months ago)

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

hello said: (50 months ago)


Leissa Schriever said: (46 months ago)

Lord Inglip be praised.

Jg said: (45 months ago)


Jggydfh said: (45 months ago)

Recaptcha sucks and i can pwn it

herp said: (44 months ago)


testing said: (44 months ago)


hi said: (23 months ago)


test said: (17 months ago)


aaoisd said: (15 months ago)


noasin said: (15 months ago)


Leave a comment