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

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

# coding:utf8

from django.dispatch import Signal
from django.dispatch import receiver

custom_signal = Signal()




class Demo2:

    def __init__():
        print "__init__"
    pass

class Demo:

    def __init__():
        print "__init__"
    pass

def 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的发送和接收样例

上一篇:element-plus 自动导入导致message样式错误


下一篇:spring中使用@ResponseBody注解返回json,Long类型精度丢失