Skip to main content

Pyramid Captcha

Project description

Pyramid Captcha

This Python package provides a captcha implementation for use with the Pyramid Web Framework. It is based on the captcha library and uses Pyramid sessions for captcha validation. Please refer to the documentation for further information.

Usage

To generate a captcha, you have to import the class Captcha.

from pyramid_captcha import Captcha

The simplest solution is to use this class directly in your view definition.

config.add_route('captcha_generate', '/captcha')
config.add_view(
    Captcha,
    attr='generate',
    route_name='captcha_generate',
    request_method='GET'
)

In this case, the route /captcha will return a captcha image with the default length of 6 characters. If you want to adjust the captcha properties, you have to wrap it into a view callable, for example to change the number of characters.

def generate(request):
    return Captcha(request, length=4).generate()

The generated captcha value is stored in the current session. It can be checked against a submitted form value using the validate() method.

try:
    Captcha(request).validate()
except CaptchaError as e:
    raise HTTPForbidden(e)

Demo

You can check out the code and run a little demo by calling make serve.

Changelog

1.0.0

https://gitlab.com/geo-bl-ch/pyramid-captcha/-/milestones/1

  • Add parameter for value validation

  • Configurable captcha length

  • Initial version

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyramid_captcha-1.0.0.tar.gz (4.4 kB view hashes)

Uploaded Source

Built Distribution

pyramid_captcha-1.0.0-py3-none-any.whl (4.6 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page