Skip to main content

Django Friendly Captcha

image PyPI - Downloads image Ruff

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

[!NOTE] FRC_CAPTCHA_VERSION defaults to 'v1', so if you omit this setting or set to None v1 is used. There's no need to take any action if you stick to version 1.

v1

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

FRC_CAPTCHA_VERSION = 1  # or '1'
FRC_CAPTCHA_SECRET = '<yourCaptchaSecret'
FRC_CAPTCHA_SITE_KEY = '<yourCaptchaSiteKey>'

There's no need to specif the captcha verification URL anymore, this is handled automatically.

v2

Instead of a secret you now get new API-Key with your registration. If you're already registered reach out to the friendly-captcha Website to get your API-Key.

FRC_CAPTCHA_VERSION = 2  # or '2'
FRC_CAPTCHA_API_KEY = '<yourCaptchaApiKey'
FRC_CAPTCHA_SITE_KEY = '<yourCaptchaSiteKey>'

There's also a new setting to specify the endpoint region ("EU" or "global"). Please note that you need to have a special plan to choose a special endpoint. (See the friendly captcha docs for more information).

FRC_CAPTCHA_ENDPOINT = 'eu | global'

The setting defaults to 'global'.

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 ...

If the captcha response returns with some http code other than 200, that doesn't mean the captcha result is invalid, it simply wasn't able ot resolve the puzzle (because i.e. the friendly-captcha server is down or there are network problems). You can specify how to deal with those responses by setting

FRC_CAPTCHA_ACCEPT_UNVERIFIED = False|True

FRC_CAPTCHA_ACCEPT_UNVERIFIED defaults to False.

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 value 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-theme': 'dark'}))

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',
}

Metadata

Release files for django-friendly-captcha 0.2.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-friendly-captcha 0.2.3
File Size Uploaded
django_friendly_captcha-0.2.3.tar.gz 10.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for django-friendly-captcha 0.2.3
File Interpreter ABI Platform
django_friendly_captcha-0.2.3-py3-none-any.whl Python 3 none any Details

Total release size: 22.8 kB

Release files / django_friendly_captcha-0.2.3.tar.gz

Download URL django_friendly_captcha-0.2.3.tar.gz
Size 10.1 kB
Tags Source
SHA-256 checksum
How to use checksums
fec52aa46b82867bf5f017b5974b4436655f182133f2a4655a291b39e1b5cec1
BLAKE2b-256 checksum
How to use checksums
b50696ee85856e99c2a6c1b26796c757c98e2710f4a2ce4b8d2bbe471905a3c1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / django_friendly_captcha-0.2.3-py3-none-any.whl

Download URL django_friendly_captcha-0.2.3-py3-none-any.whl
Size 12.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
cd353a49cc249e9ca33411b8f941764cc681ae7b4ed6dd6098fc0074244ad958
BLAKE2b-256 checksum
How to use checksums
dabd37c952bcd219f997e912b052b76638bd1f2a7483f121493b2eca36c86f3e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release history Release notifications | RSS feed

This release

0.2.3 This release

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.14

2 release files

0.1.13

2 release files

0.1.12

2 release files

0.1.11

2 release files

0.1.10

2 release files

0.1.9

2 release files

0.1.8

2 release files

0.1.7

2 release files

0.1.6

2 release files

0.1.5

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page