a. 定义信号

1

2

import django.dispatch

pizza_done = django.dispatch.Signal(providing_args=["toppings", "size"])

 b. 注册信号

1

2

3

4

5

def callback(sender, **kwargs):

    print("callback")

    print(sender,kwargs)

  

pizza_done.connect(callback)

 c. 触发信号

1

2

3

from 路径 import pizza_done

//sender可以为models类

pizza_done.send(sender='seven',toppings=123, size=456)