2007-10-25

How to integrate reCAPTCHA with Django

1. Sign up with reCAPTCHA for get public and private key.
2. Download reCAPTCHA for Python.
3. Copy captcha.py to location in your PYTHON_PATH so that you can import it. (e.g /usr/local/python2.5/Lib/site/packages)
4. Now your Django site can use reCAPTCHA.
in your view use reCAPTCHA like this.

import capcha

def captcha_view(request):
captcha.displayhtml(RECAPTCHA_PUB_KEY) # use for display reCAPTCHA in template.
captcha_obj = captcha.submit( request.POST['recaptcha_challenge_field'],
request.POST['recaptcha_response_field'],
RECAPTCHA_PRIVATE_KEY,
request.META['REMOTE_ADDR'] ) # use for create captcha object for check result.
if captcha_obj.is_valid:
return success
else:
return error

2007-10-06

How to use MySQL RegExp

You can use RegExp in MySQL like this.
- SELECT column_name FROM table_name WHERE column_name COLLATE utf8_bin REGEXP '^.* [a-zI]$'

Note: COLLATE is use for use case sensitive in SQL.