Usage¶
Honeypot field¶
Honeypot is a spam protection technique to detect and block automatic spam spiders on your website. Also known as spamtrap technique.
See also
You can read more about this technique at Wikipedia.
Form protection is very simple, just add a HoneypotField
to your form:
from django import forms
from antispam.honeypot.forms import HoneypotField
class MyForm(forms.Form):
name = forms.CharField()
spam_honeypot_field = HoneypotField()
HoneypotField uses standard form validation behaviour.
If spam submit was detected - ValidationError
with spam-protection
code will be raised.
CAPTCHA¶
CAPTCHA – Completely Automated Public Turing test to tell Computers and Humans Apart. We support CAPTCHA implementation called reCAPTCHA V2.
reCAPTCHA V2¶
reCAPTCHA is a free service that protects your website from spam and abuse. reCAPTCHA uses an advanced risk analysis engine and adaptive CAPTCHAs to keep automated software from engaging in abusive activities on your site.
See also
You can read more at google reCAPTCHA official website.
To use reCAPTCHA protection in your project form, obtain keys from Google <https://www.google.com/recaptcha/admin>, add them to SETTINGS
:
RECAPTCHA_SITEKEY = 'sitekey'
RECAPTCHA_SECRETKEY = 'secretkey'
and add ReCAPTCHA
field:
from django import forms
from antispam.captcha.forms import ReCAPTCHA
class MyForm(forms.Form):
name = forms.CharField()
captcha = ReCAPTCHA()
- django-antispam package provides 2 widgets of reCAPTCHA:
antispam.captcha.widgets.ReCAPTCHA
- default reCAPTCHA v2 widgetantispam.captcha.widgets.InvisibleReCAPTCHA
- invisible reCAPTCHA widget
To display reCAPTCHA on website page, you should add reCAPTCHA script into the template:
{% load recaptcha %}
{% block head %}
...
{% recaptcha_init %}
{% endblock %}