我有一个未运行的自定义连接信号:

方法add_participant中的竞赛模型中的代码:

            # this is called and no error happens
            contest_after_added_participant.send(sender=self, 
                                           participant=participant, 
                                           participation=participation)

竞赛模型存在的文件中的代码:

def my_callback(sender, **kwargs):
    sender.title += 'sss' # this is never called

contest_after_added_participant = Signal(providing_args=["participant", "participation"])
contest_after_added_participant.connect(my_callback, sender=Contest, dispatch_uid='Contest.001')

===============>>#1 票数:2

发送发件人kwarg时应将类Contest而不是Contest的实例。 校验:

contest_after_added_participant.send(sender=Contest, 
                                 participant=participant, 
                                 participation=participation)

===============>>#2 票数:1

您的错误是,您使用Contest 的“ sender”参数调用.connect(),而使用Contest 实例调用.send(),因此它们不匹配。 如果您只有一个侦听器来接收自定义信号,而无需过滤特定发件人发送的信号,如下所述: https : //docs.djangoproject.com/en/dev/topics/signals/#connecting-to-signals -send-by-specific-senders ,那么您也可以从.connect()调用中删除“ sender”参数:

contest_after_added_participant.connect(my_callback, dispatch_uid='Contest.001')

  ask by Totty.js translate from so

未解决问题?本站智能推荐: