Django的。为什么我的信号功能不起作用? [重复]

时间:2022-08-23 14:48:43

This question already has an answer here:

这个问题在这里已有答案:

I got a model named Request with a few fields in models.py. I also got signal receiver in signals.py:

我在models.py中有一个名为Request的模型,其中包含几个字段。我还在signals.py中有信号接收器:

@receiver(post_save, sender=Request)
def status_changed(sender, **kwargs):
    "doing smth"

But when I am trying to change some fields of Request model in admin interface and then press "save", receiver didnt catch any signals and my function "status_changed" doesn't run. What kind of problem it might be and how may I solve it?

但是当我试图在管理界面中更改Request模型的某些字段然后按“save”时,接收器没有捕获任何信号,我的函数“status_changed”没有运行。它可能是一个什么样的问题,我该如何解决它?

Thank you in advance.

先感谢您。

1 个解决方案

#1


0  

This happens because you never include the signals file anywhere. You should include them in your models.py and or make sure that at least one of your files registers them in order to get fired at some point. The simplest solution would be to copy all of your signals at the end of your models.py file and see what happens.

这是因为您从未在任何地方包含信号文件。您应该将它们包含在models.py中,或者确保至少有一个文件注册它们以便在某些时候被解雇。最简单的解决方案是在models.py文件的末尾复制所有信号,看看会发生什么。

#1


0  

This happens because you never include the signals file anywhere. You should include them in your models.py and or make sure that at least one of your files registers them in order to get fired at some point. The simplest solution would be to copy all of your signals at the end of your models.py file and see what happens.

这是因为您从未在任何地方包含信号文件。您应该将它们包含在models.py中,或者确保至少有一个文件注册它们以便在某些时候被解雇。最简单的解决方案是在models.py文件的末尾复制所有信号,看看会发生什么。