Django 关于评论提交的通知
我正在使用 Django 的 contrib.comments 并想了解以下内容。
是否有任何实用程序或应用程序可以插入到应用程序中,以便在某个项目上发表评论时向您发送通知?
我还没有真正接触过信号那么多,所以请稍微描述一下。
这就是我想出来的。
from django.contrib.comments.signals import comment_was_posted
from django.core.mail import send_mail
if "notification" in settings.INSTALLED_APPS:
from notification import models as notification
def comment_notification(request):
user = request.user
message = "123"
notification.send([user], "new comment", {'message': message,})
comment_was_posted.connect(comment_notification)
I am making use of Django's contrib.comments and want to know the following.
Are there any utils or app out there that can be plugged into an app that sends you a notification when a comment is posted on an item?
I haven't really worked with signals that much, so please be a little bit descriptive.
This is what I came up with.
from django.contrib.comments.signals import comment_was_posted
from django.core.mail import send_mail
if "notification" in settings.INSTALLED_APPS:
from notification import models as notification
def comment_notification(request):
user = request.user
message = "123"
notification.send([user], "new comment", {'message': message,})
comment_was_posted.connect(comment_notification)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
将
django.contrib.comments.signals.comment_was_posted
连接到通知
.models.send()
(视情况而定)。Connect
django.contrib.comments.signals.comment_was_posted
tonotification
.models.send()
as appropriate.您必须使用
comment_was_posted
信号注册您的comment_notification
函数。You have to register your
comment_notification
function withcomment_was_posted
signal.我不知道有什么应用程序(很确定会有一些应用程序),但推出自己的应用程序相当简单。您可以点击
Comment
模型的comment_was_posted
信号调用将向您发送电子邮件的函数。I don't know of an app (pretty sure there'll be something out there) but it is fairly straightforward to roll your own. You can tap the
Comment
model'scomment_was_posted
signal to call a function that will send you an email.