Skip to main content

Django library for friendly captcha

Project description

https://img.shields.io/pypi/v/django-friendly-captcha PyPI - Downloads

Django field/widget for Friendly Captcha (https://friendlycaptcha.com).

Installation

Latest version:

pip install -e git+git://github.com/christianwgd/django-friendly-captcha.git#egg=django-friendly-captcha

Stable version:

pip install django-friendly-captcha

Documentation

Usage

Add ‘friendly_captcha’ to your INSTALLED_APPS.

INSTALLED_APPS = [
    ...
    'friendly_captcha',
]

Add the captcha field to your form:

from friendly_captcha.fields import FrcCaptchaField


class ContactForm(forms.ModelForm):

    class Meta:
        model = ContactMessage
        fields = (
            'name', 'email', 'subject', 'text'
        )

    captcha = FrcCaptchaField()

As of version 0.1.7 the javascript static assets are included in the widget, so there is no need to do that in your project templates. Version 0.1.10 includes friendly captcha version 0.9.15 javascript files. If you need a different version you can set these by providing them in your settings:

FRC_WIDGET_MODULE_JS = 'https://unpkg.com/friendly-challenge@0.9.8/widget.module.min.js'
FRC_WIDGET_JS = 'https://unpkg.com/friendly-challenge@0.9.8/widget.min.js'

For version 0.1.6 and below you need to include the script tags from Friendly Captcha to your forms template (see https://docs.friendlycaptcha.com/#/installation)

<script type="module" src="https://unpkg.com/friendly-challenge@0.9.8/widget.module.min.js" async defer></script>
<script nomodule src="https://unpkg.com/friendly-challenge@0.9.8/widget.min.js" async defer></script>

If you build up your form from single fields, dont’t forget to include the captcha form field.

Configuration

Register to Friendly Captcha at https://friendlycaptcha.com/signup to get your sitekey and captcha secret.

FRC_CAPTCHA_SECRET = '<yourCaptchaSecret'
FRC_CAPTCHA_SITE_KEY = '<yourCaptchaSiteKey>'
FRC_CAPTCHA_VERIFICATION_URL = 'https://api.friendlycaptcha.com/api/v1/siteverify'

In default the form will fail with an error (‘Captcha test failed’). You can change this behaviour by setting FRC_CAPTCHA_FAIL_SILENT to True.

FRC_CAPTCHA_FAIL_SILENT = False

When setting FAIL_SILENT to True it’s up to you to handle captcha verification:

# in your form view
def form_valid(self, form):
    captcha_verified = form.cleaned_data['captcha']
    if captcha_verified:
        # send mail or whatever ...
    else:
        # captcha verification failed, do nothing ...

As of version 0.1.11 there’s a new settings option to get a mocked value from the captcha verification. You can set FRC_CAPTCHA_MOCKED_VALUE to True or False, depending on the vaule you need for testing. The default value is unset which equals to None.

FRC_CAPTCHA_MOCKED_VALUE = None|False|True

Custom widget attributes

You can add custom widget attrs to the FrcCaptchaField like in any other Django field:

captcha = FrcCaptchaField(widget=FrcCaptchaWidget(attrs={'data-start': 'auto'}))

See https://docs.friendlycaptcha.com/#/widget_api for additional widget attrs. The data-lang attr is set from your Django configured language.

Logging

If you want to log the results of the captcha verifications you can add a logger to your logging configuration:

'django.friendly_captcha': {
    'handlers': ['default'],
    'level': 'INFO',
}

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

django_friendly_captcha-0.1.13.tar.gz (6.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

django_friendly_captcha-0.1.13-py3-none-any.whl (9.1 kB view details)

Uploaded Python 3

File details

Details for the file django_friendly_captcha-0.1.13.tar.gz.

File metadata

File hashes

Hashes for django_friendly_captcha-0.1.13.tar.gz
Algorithm Hash digest
SHA256 2b6dd8955bfb3662d339d0edd1eb40cdcc471a5725cb7c420ae6b2c01a28bb09
MD5 56bc0ec8f6c6f9465b733813d0a47b6f
BLAKE2b-256 0139777d320cc94b249429ecd1cdb2fe00f622ec19f895b05b7f95d45e932e46

See more details on using hashes here.

File details

Details for the file django_friendly_captcha-0.1.13-py3-none-any.whl.

File metadata

File hashes

Hashes for django_friendly_captcha-0.1.13-py3-none-any.whl
Algorithm Hash digest
SHA256 b8a3436fc52fbb607e31776269ccf1dd82f4723cd2ba40200857d90bed0463d9
MD5 0e42665294be946cc141c0878b6834f5
BLAKE2b-256 560c956f3acb7e66d88240fb4aaaa37d0c7a8f21186219e8887e7eff4a4f9f57

See more details on using hashes here.

Supported by

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