Django Signals

Built-in Signals

Django provides a set of built-in signals that let user code get notified by Django itself of certain actions. These include some useful notifications:

See the built-in signal documentation for a complete list, and a complete explanation of each signal.

Listen to Signals

To receive a signal, register a receiver function using the Signal.connect() method. The receiver function is called when the signal is sent:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
# 函数原型
Signal.connect(receiver, sender=None, weak=True, dispatch_uid=None)
"""
参数说明:
- receiver: 信号发生的回调函数
  See [Receiver functions](https://docs.djangoproject.com/en/2.1/topics/signals/#receiver-functions)

- sender: 指定一个信号的发生者
  See [Connecting to signals sent by specific senders](https://docs.djangoproject.com/en/2.1/topics/signals/#connecting-to-specific-signals)
  
- weak: 暂时没看懂,反正默认是 True 就对了

- dispatch_uid: 在可能发生重复信号的情况下设置接受器的唯一标识
"""