Quick start¶
These are the basic steps for using djangospam. You can get more info on the cited modules and at djangospam.settings.
Fake form with cookie middleware¶
New in version 0.3.0.
The cookie middleware uses cookies to identify known spam bots. Simple crawlers usually don’t accept cookies, but spam bots may accept, since a website may require this to receive comments. In order to use the cookie middleware, add djangospam.cookie.middleware.SpamCookieMiddleware to MIDDLEWARE_CLASSES at your settings file (usually settings.py). In your template, insert before the true form:
{% include 'djangospam/cookieform.html' %}
You must also add (r”^somewhere/”, include(“djangospam.cookie.urls”) to your url patterns (usually in your root urls.conf; somewhere may be any path, except the one used for true posts). I suggest using the following paths:
(r'^comments/', include('djangospam.cookie.urls')),
(r'^spam/', include('django_comments.urls')),
Fake form without middleware¶
You may also use the fake form without the cookie middleware. This will not block access from known spam bots. In order to do this, include djangospam in your installed modules (at settings.py) and insert the following code in your template, before the true form:
{% include 'djangospam/form.html' %}
You may also define a spam_uri context variable with the fake formulary destination URI. If no URI is defined, the form will be posted at the same address of the page in which the form has been placed (it will be used a <form method-“post” action-“”>...</form> code). The destination address must accept POST requests and should not change the database.
You may customize the fake formulary by copying it’s template to template/djangospam at your application’s directory and editing it.
Cookie-based moderator¶
New in version 0.4.0.
djangospam.cookie.moderator defines a cookie-based comment moderator that should be attached to your commented model. This moderator tests comment post requests for the djangospam cookie and discards those which don’t have it. See djangospam.cookie.middleware for more info on the cookie system. Code that uses this comment moderator must use that middleware.
Your models file should be like this:
from djangospam.cookie import moderator as cookie
class MyModel(...):
...
try:
cookie.register(MyModel)
except cookie.AlreadyModerated:
pass