Skip to content

AlexRazzoR/django-antispam

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 

Repository files navigation

Django Anti-Spam Middleware

Middleware for protecting Django forms against spam using CleanTalk service.

Installation

  1. Install the package:
    pip install cleantalk-python-antispam
    
  2. Add your CleanTalk API key to settings.py:
    CLEANTALK_API_KEY = "your_api_key_here"
  3. Add the middleware to your MIDDLEWARE (typically at the end)::
    MIDDLEWARE = [
       ...
       'path.to.AntiSpamMiddleware',
    ]
  4. For time submission checks, add this to your form handling:
    request.session["ct_timestamp"] = int(time.time())

Usage

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)

Configuration

The middleware checks these form fields by default:

  • email - user's email address
  • message - message text
  • name - user's name
  • ct_js_on - JavaScript enabled flag (1/0)

Customize the data dictionary in the middleware to adjust field mapping.

Important Notes

For proper form submission time checking (submit_time):

  1. Set the timestamp in session when displaying the form
  2. Ensure Django sessions are properly configured

Requirements

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages

  • Python 100.0%