Django 关于评论提交的通知

发布于 2024-09-25 05:53:07 字数 584 浏览 12 评论 0原文

我正在使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

痞味浪人 2024-10-02 05:53:07

django.contrib.comments.signals.comment_was_posted 连接到 通知.models.send()(视情况而定)。

Connect django.contrib.comments.signals.comment_was_posted to notification.models.send() as appropriate.

冬天旳寂寞 2024-10-02 05:53:07

您必须使用 comment_was_posted 信号注册您的 comment_notification 函数。

from django.contrib.comments.signals import comment_was_posted

if "notification" in settings.INSTALLED_APPS:
    from notification import models as notification

    def comment_notification(sender, comment, request):
        user = request.user
        message = "123"
        notification.send([user], "new comment", {'message': message,}) 

    comment_was_posted.connect(comment_notification)

You have to register your comment_notification function with comment_was_posted signal.

from django.contrib.comments.signals import comment_was_posted

if "notification" in settings.INSTALLED_APPS:
    from notification import models as notification

    def comment_notification(sender, comment, request):
        user = request.user
        message = "123"
        notification.send([user], "new comment", {'message': message,}) 

    comment_was_posted.connect(comment_notification)
随梦而飞# 2024-10-02 05:53:07

我不知道有什么应用程序(很确定会有一些应用程序),但推出自己的应用程序相当简单。您可以点击 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's comment_was_posted signal to call a function that will send you an email.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文