开发者

Django "comment_was_flagged" signal

This is my first time working with django signals and I would like to hook the "comment_was_flagged" signal provided by the comments app to notify me when a comment is flagged.

This is my code, but it doesn't seem to work, am I missing something?

from django.contrib.comments.signals import comment_was_flagged
from django.core.mail import send_mail

def comment_flagged_notification(sender, **kwargs):
  send_mail('testing moderation', 'testing', 'test@localhost', ['myemail@gmail.com',])

comment_was_flagged.co开发者_JAVA百科nnect(comment_flagged_notification)

(I am just testing the email for now, but I have assured the email is sending properly.)

Thanks!


I'm guessing you've thrown this code in a signals.py module, or something similar.

You have to make sure your module code is actually getting executed at runtime. If none of your model modules import your signals module, your signal listeners won't be getting connected.

Stealing a snippet from Django's signals documentation:

... you'll need to make sure that the module it's in gets imported early on so that the signal handling gets registered before any signals need to be sent. This makes your app's models.py a good place to put registration of signal handlers.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜