2012-10-11 135 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