Django-Notification - 电子邮件后端的替代方案
我正在使用 Django 构建一个项目,目前正在尝试实现 django-notification 作为跟踪用户活动的方法。虽然我设法安装它并创建一些通知,但它们仅通过电子邮件发送,而不存储在相应的数据库中,以便我可以在提要视图中显示它们。
/notifications/feed/ 当前给我一个类型错误,我不确定这是否相关?
/notifications/feed/ 处的类型错误 init() 正好需要 3 个参数(给定 1 个参数)
如有任何建议,我们将不胜感激。我研究过 Pinax 如何使用通知,但不明白它们如何超越仅电子邮件后端。
在settings.py中,我启用了“通知”,以及template_context_processor“notification.context_processors.notification”。
urls.py
url(r'^note/', include('notification.urls')),
app/management.py
if "notification" in settings.INSTALLED_APPS:
from notification import models as notification
def create_notice_types(app, created_models, verbosity, **kwargs):
notification.create_notice_type("messages_received", _("Message Received"), _("you have received a message"), default=2)
signals.post_syncdb.connect(create_notice_types, sender=notification)
app/view.py
...
if notification:
notification.send([user], "messages_received", {'message': message,})
...
notification.send 已执行,我检查了这一点,但似乎“通知”数据库中没有存储任何内容..
我应该添加,我正在运行 Brian Rosner 分支django-notification (https://github.com/brosner/django-notification)。
I'm building a project with Django, and am currently trying to implement django-notification as a means to keep track of user activity. While I managed to install it and create some notifications, they are only sent via email but not stored in the respective databases so that I could display them in a feed view.
The /notifications/feed/ currently gives me a type error, I'm not sure if that is related?
TypeError at /notifications/feed/
init() takes exactly 3 arguments (1 given)
Any advice would be kindly appreciated. I've looked at how Pinax uses notification, but couldn't figure out how they got beyond the email-only backend.
In settings.py I have 'notification' enabled, as well as the template_context_processor 'notification.context_processors.notification'.
urls.py
url(r'^note/', include('notification.urls')),
app/management.py
if "notification" in settings.INSTALLED_APPS:
from notification import models as notification
def create_notice_types(app, created_models, verbosity, **kwargs):
notification.create_notice_type("messages_received", _("Message Received"), _("you have received a message"), default=2)
signals.post_syncdb.connect(create_notice_types, sender=notification)
app/view.py
...
if notification:
notification.send([user], "messages_received", {'message': message,})
...
notification.send is executed, I checked this, but it seems that nothing is stored in the "notice" database ..
I should add, I'm running the Brian Rosner branch of django-notification (https://github.com/brosner/django-notification).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看来 brosner 的 django-notifications 分支与 jtauber 的不同之处在于
send_now()
实际上并不将通知实例添加到数据库,默认的EmailBackend
通知后端也没有。您必须编写自己的通知后端类,该类在调用
deliver()
时创建一个通知实例,并将其添加到NOTIIFICATION_BACKENDS
中。复制 jtauber 行为的(未经测试的)示例:
It appears that brosner's fork of django-notifications differs from jtauber's in that
send_now()
does not actually add Notice instances to the database, nor does the defaultEmailBackend
notification backend.You will have to write your own notification backend class that creates a Notice instance when
deliver()
is called, and add it toNOTIIFICATION_BACKENDS
.An (untested) example replicating jtauber's behavior: