2012-10-26 101 views
1

我昨天實施了評論框架,它的運行效果很好。不過,我已經設置了一個小腳本,以便在發佈評論時收到電子郵件,以便我可以發佈評論。不過,昨天晚上,我收到了來自機器人上的20封垃圾郵件。我檢查了Google Analytics,昨天我有28頁面瀏覽量和6個獨特的視圖。所以它看起來像1個或2個機器人並且已經多次填充表格。Django評論垃圾郵件過濾器

當我查看網站上的源代碼時,'honey pot'字段在那裏,所以我不確定爲什麼這會阻止垃圾郵件。我想知道是否我的代碼中缺少蜜罐/垃圾郵件過濾器的某些功能?

這裏是我的表單的所有代碼,我相當新的Django不,它可能是我錯過了任何東西。由於網站上的流量不是很高,我沒有看到實施第三方垃圾郵件過濾器的原因。

/// FORM

{% get_comment_form for notice as form %} 
    <div id="comment_wrap"> 

    <h1>Comments</h1> 
    {% get_comment_list for notice as comment_list %} 
    {% get_comment_count for notice as comment_count %} 
    <h2>{{comment_count}} comment{{ comment_count|pluralize:"s"}}</h2> 
    <form action="{% comment_form_target %}" method="post"> 

    <table> 
    <tr> 

    <td> 
    {{ form.comment.errors }} 
    <div class="add"> 
     <textarea id="id_comment" name="comment" value="Add a comment...">Add a comment...</textarea></div> 
    </td> 
    </tr> 
    </table> 

    <table> 
    <tr> 
     {{ form.non_field_errors }} 
     <td height="30"> 

    {{ form.name.errors }} 
    <div class="name"><input id="id_name" type="text" maxlength="50" name="name" value="Name"></div> 

     </td> 

     <td> 
    {{ form.company.errors }} 

    <div class="company"> 
     <input type="text" maxlength="50" name="company" id="id_company" value="Company"> 
    </div> 


     </td> 



     <input type="hidden" name="url" value="http://www.website.org" /> 
     <input type="hidden" name="email" value="[email protected]" /> 


     <td> 
    <input type="hidden" name="next" value="{{notice.get_absolute_url}}#commentmade"/> 

    <button class="submit" value="Submit" >Submit</button> 

     </td> 
    </tr> 
    </table> 

    <div id="commentmade" style="display: none;"><p>Thanks for posting. Your comment is awaiting approval.</p></div> 
    <div class="fieldWrapper honey_pot"> 
    {{ form.honeypot.errors }} 
    <label for="id_honeypot">If you enter anything in this field your comment will be treated as spam:</label> 
    {{ form.honeypot }} 
    {{ form.content_type.errors }} 
    {{ form.content_type }} 

    {{ form.object_pk.errors }} 
    {{ form.object_pk }} 

    {{ form.timestamp.errors }} 
    {{ form.timestamp }} 

    {{ form.security_hash.errors }} 
    {{ form.security_hash }} 
</div> 

    </form> 

    </div> 




    {% for comment in comment_list reversed %} 
    <div id="comment_post"> 
    <span class="name">{{comment.user_name}}</span> 
    <span class="company"> | {{comment.company}} | </span> 
    <span class="time">{{comment.submit_date|timesince}}</span> 
    <p>{{comment.comment}}</p> 


    </div> 
    {% endfor %} 
+1

您將需要發佈查看代碼 –

+0

有沒有?我使用的是內置評論功能的Djangos。我唯一的視圖代碼是擴展字段的視圖代碼。我可以發佈,但我不明白這將有什麼幫助? – JDavies

回答

2

honeypot只是一個隱藏的填補,這很可能是由一個機器人而不是一個真正的用戶來填充。

當蜜罐有一個值時,表單不驗證。

也許像Akismet這樣的解決方案,例如集成在django-akismet中,可以幫助您更多。

+0

好的,謝謝,這可能是爲什麼它全部通過。我注意到有幾個人提到Akismet,所以可能會嘗試。 'csrf token'會有幫助嗎?不太確定這是如何工作的,但我並沒有把它列入我的表格。 – JDavies

+0

獲取csrf標記很容易。 csrf令牌用於防止基本的XSS攻擊。 – jpic