django - 如何在 post_save 函数中获取请求
问题描述
您好,我正在使用 Post_save 信号从模型发送通知....
但我收到这样的错误“sending_notification() 缺少 1 个必需的位置参数:'request'”
@receiver(post_save, sender=Plan)
def sending_notification(request, sender, instance,created, **kwargs):
if created:
notify.send(request.user, recipient = request.user, verb = "Some messages")
解决方案
您不能在那里访问请求,从信号参数中删除请求。
@receiver(post_save, sender=Plan)
def sending_notification(sender, instance, created, **kwargs):
if created:
pass
我在这里看到了您要实现的目标,您正在使用 django-notifications-hq 向用户发送通知,您可以在视图本身中执行此操作,因为请求在模型信号中不可用。
推荐阅读
- javascript - 如何使用从exports.default 函数传递的变量
- python - 将两列组合在一起作为列表数据类型,并从抑制 json 文件中过滤掉单词
- sql-server - 重新登录无法通过 t-sql xp_commandshell 工作,但相同的命令在命令提示符下工作
- eclipse - Create new instance of a project in intellij
- javascript - TypeError: _fieldRef$current.blur 不是函数
- firebase - Flutter/Firebase - type 'Future
' is not a subtype of type 'int' - c - Generate integer random number using available binaryrandom (which return 0 or 1) function
- python - How to resolve graph2vec error invalid literal for int()?
- android - 使用 ViewModel 未在 Webview 中加载 URL
- python - While trying to display wav file using scipi im getting the following error "ushort format requires 0 <= number <= 0xffff"