Django library for friendly captcha
Project description
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()
Add 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>
I thought about adding these static assets as form media assets, but users wouldn’t be able to choose the desired version. So I decided against for now.
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 ...
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for django-friendly-captcha-0.1.6.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 659db68be259e7495a8e08b8c3b45cf27871894f30642a46a243574fe986a7ff |
|
MD5 | 13b0083c1e66f02d61f4e8ef50a009de |
|
BLAKE2b-256 | f8a23eb468090c8ef7ced7853a707edb4d593409c7e1f12dc115debd718611dd |
Hashes for django_friendly_captcha-0.1.6-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 07163bc10acca88d0afb0e8d0fc857823097e4d76731d9a2f70fbc0ef67d7881 |
|
MD5 | c4f966b30e54e63947eee018ec4b529f |
|
BLAKE2b-256 | 2c4047031904ffa6b829a7e2897f6b4db2a2e27b2922e89ed1ab4e3894a25fbd |