Middleware for protecting Django forms against spam using CleanTalk Anti-Spam service. ClanTalk is a cloud-based anti-spam service, invisible protection without using captcha or rcaptcha, puzzles, or math captcha.
Key features:
Real-time Spam & Bot Protection
- Automatic Email Validation to eliminate fake or erroneous registrations
- Personalized Blocklists by IP, email, and country
- Custom Stop Words for fine-tuned spam filtering
- Easy and seamless integration
- Enjoy comprehensive spam protection and hassle-free user experience—no CAPTCHA/reCAPTCHA needed.
- The anti-spam service log allows you to control the service's decision and check each request.
The CleanTalk cloud service provides flawless and automatic protection of websites from spam. It works in the background, analyzing the behavior of visitors and evaluating data sent via forms.
Once installed, it begins to track the behavior of each visitor - whether a real user or a bot. Based on this behavior, CleanTalk determines whether to allow the message or block it as spam. During this process, the system forms its own database of email addresses associated with spam. The system also checks user registrations and tracks not only email addresses, but also IP addresses and domains used to send spam.
CleanTalk has developed its own algorithms that analyze user behavior, ensuring effective spam blocking. The entire process is fully automated and does not require manual intervention from the site administrator.
- Install the package:
pip install cleantalk-python-antispam
- Add your CleanTalk API key to
settings.py
:CLEANTALK_API_KEY = "your_api_key_here"
- Add the middleware to your
MIDDLEWARE
(typically at the end)::MIDDLEWARE = [ ... 'path.to.AntiSpamMiddleware', ]
- For time submission checks, add this to your form handling:
request.session["ct_timestamp"] = int(time.time())
The middleware automatically checks all POST requests. When spam is detected:
- Sets
request.cleantalk_blocked
flag with CleanTalk's response message - By default doesn't block the request (uncomment the line to enable blocking)
The middleware checks these form fields by default:
email
- user's email addressmessage
- message textname
- user's namect_js_on
- JavaScript enabled flag (1/0)
Customize the data
dictionary in the middleware to adjust field mapping.
For proper form submission time checking (submit_time
):
- Set the timestamp in session when displaying the form
- Ensure Django sessions are properly configured
- CleanTalk account https://cleantalk.org/register?product=anti-spam