首页 > 代码库 > django自定义signal的发送和接收样例

django自定义signal的发送和接收样例

想在项目中用上,就实习一下。

# coding:utf8from django.dispatch import Signalfrom django.dispatch import receivercustom_signal = Signal()class Demo2:    def __init__():        print "__init__"    passclass Demo:    def __init__():        print "__init__"    passdef ak():    pass@receiver(custom_signal, sender=ak)def my_callback(sender, **more):    print sender    print more    print "my callback called"@receiver(custom_signal)def my_callback(sender, **more):    print sender    print more    print "my callback called"custom_signal.send_robust(sender=ak,  aa=1, bb=2)custom_signal.send(sender=Demo2,  cc=1, dd=2)

技术分享

django自定义signal的发送和接收样例