My favorites | Sign in
Project Home Downloads Wiki Issues Source
Project Information
Members

Captchas in django forms using pycaptcha lib

Intro

Using the captcha field:

from captchas.fields import CaptchaField

class CaptchaContactForm(ContactForm):
    # ...
    captcha = CaptchaField(label='Robot test')

Screenshot:

You can cutomize your captcha's size, font, backgrounds or word list by creating your own ImageCaptcha class.

import random

from Captcha.Visual import Text, Backgrounds, Distortions, !ImageCaptcha
from Captcha.Words import WordList


class SmallerCaptcha(ImageCaptcha):
    defaultSize = (130,50)

    def getLayers(self):
        word = WordList('basic-english').pick()
        self.addSolution(word)
        return [random.choice([Backgrounds.CroppedImage(), Backgrounds.TiledImage()]),
                Text.TextLayer(word, borderSize=1, fontFactory=Text.FontFactory(18, "vera/VeraBd.ttf")),
                Distortions.SineWarp()]
Powered by Google Project Hosting