This has only been tested with the standard Django comments framework.
Two modules are included:
- middleware: adjusts the request metadata so Django uses the end-user's IP address and not CloudFlare's
- admin: adds a Report spam to CloudFlare action to the Django Administration Interface for Comments
I'm assuming below that you drop this directly into a 'cloudflare' directory in your project. I know this isn't really cool and will (maybe) take a look at packaging this better later.
Adjust your project's
settings.py as follows:
Add the middleware to
MIDDLEWARE_CLASSES = ( 'django.middleware.common.CommonMiddleware', # ... 'yourproject.cloudflare.middleware.CFMiddleware', # <- This is it! )
INSTALLED_APPS = ( 'django.contrib.admin', 'django.contrib.comments', # ... 'yourproject.cloudflare' # <- This is it! )
Add your CloudFlare account credentials
# CloudFlare credentials for reporting spam CLOUDFLARE_API_KEY = '08c64e15db52f0e9b4fe3418e44c0b4c6dbba9334' CLOUDFLARE_EMAIL = 'email@example.com'
I'm also assuming you have a logger configured at the project level and am hooking into that.
- Review comments in the Django Admin Interface.
- Checkmark the ones you want to report to CloudFlare.
- Select the Report spam to CloudFlare action and click Go.
- If successful, a message will flash indicating which comments have been reported (by ID).
- You can then proceed to delete or remove these using the standard comments actions.