Search code examples
pythondjangosignalsdecoratorreceiver

Django 1.8 - Signals - What's the difference between @receiver decorator and Signal.connect() method?


They appear to do the same thing. Is there a difference in functionality, usage, etc? In what circumstances should one be used over the other?

Thanks


Solution

  • @receiver is a thin wrapper around Signal.connect(). The only difference is that @receiver can accept not just a single signal, but also a list or tuple of signals, and it will connect the function to each of those signals.

    If you take a look at the source code, @receiver only calls signal.connect(func) and returns the original function.