Django“comment_was_flaged”信号
这是我第一次使用 django 信号,我想挂钩评论应用程序提供的“comment_was_flaged”信号,以便在评论被标记时通知我。
这是我的代码,但它似乎不起作用,我错过了什么吗?
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', ['[email protected]',])
comment_was_flagged.connect(comment_flagged_notification)
(我现在只是测试电子邮件,但我保证电子邮件可以正确发送。)
谢谢!
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', ['[email protected]',])
comment_was_flagged.connect(comment_flagged_notification)
(I am just testing the email for now, but I have assured the email is sending properly.)
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我猜您已将此代码放入
signals.py
模块或类似的模块中。您必须确保您的模块代码实际上在运行时执行。如果您的模型模块均未导入信号模块,则您的信号侦听器将无法连接。
从 Django 的信号文档中窃取片段:
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: