2012-10-11 57 views
0

我試圖在django評論框架上設置通知。我經過這裏的文檔不見了 -Django評論電子郵件通知

https://docs.djangoproject.com/en/dev/ref/contrib/comments/moderation/#django.contrib.comments.moderation.CommentModerator

我已經添加所有的代碼到我的布告欄應用程序,它是意見,目前正在張貼在。發佈評論時,它的網站工作正常。但是,當我點擊「啓用意見」字段,意味着允許通知,我沒有收到任何電子郵件。

**更新:

只需添加該網站有一個內置的郵件因此它記錄從該網站發送出去的所有電子郵件,它不是拿起任何的評論。如果我還取消了「啓用評論」框,我收到類似如此的錯誤消息 - comment_will_be_posted receiver'pre_save_moderation'殺死了評論

因此我知道功能正常。

這是到目前爲止,我已經得到了代碼:

//模型

from django.contrib.comments.moderation import CommentModerator, moderator 

class Notice(models.Model): 
    class Meta: 
     ordering = ['-date'] 

    content_type = 'noticeboard' 

    title = models.CharField(max_length=255) 
    sector = models.ForeignKey(BusinessSector, verbose_name="Sector", related_name='notices') 
    date = models.DateTimeField(auto_now_add=True, verbose_name="Date posted") 
    copy = models.TextField() 
    owner = models.ForeignKey('auth.User', related_name='notices') 

    owner_company = models.ForeignKey('directory.Company', verbose_name='Company') 
    enable_comment = models.BooleanField() 

class EntryModerator(CommentModerator): 
    email_notification = True 
    enable_field = 'enable_comment' 

moderator.register(Notice, EntryModerator) 

我還上傳的文件 'comment_notification_email.txt' 到模板/接觸SNIPPET。

上面的代碼已經被包括到一個exisiting應用程序稱爲布告欄,因爲這是評論被張貼在哪裏。

如果您認爲某些東西對您有用,請隨時提出任何問題。

我錯過了什麼!?

謝謝!

回答

0

我不得不在代碼中添加一個If語句來說明是否正在使用郵件發送郵件。否則它不會發送電子郵件。

if "mailer" in settings.INSTALLED_APPS: 
      from mailer import send_mail 
     else: 
      from django.core.mail import send_mail 
+0

我有同樣的問題,因爲你。你的代碼在哪裏添加了聲明?我期待使用'django.core.mail'。 – Fabian