Bird
0
0

What is wrong with this code that tries to connect a receiver to a custom signal?

medium📝 Debug Q14 of 15
Django - Signals
What is wrong with this code that tries to connect a receiver to a custom signal?
from django.dispatch import Signal

my_signal = Signal(providing_args=["data"])

def receiver_func(sender, data):
    print(f"Data: {data}")

my_signal.connect(receiver_func)
AThe receiver function must accept **kwargs, not just named arguments
BSignal must be imported from django.signals, not django.dispatch
CThe connect method requires a sender argument
Dproviding_args should be a tuple, not a list
Step-by-Step Solution
Solution:
  1. Step 1: Check receiver function signature

    Receivers must accept sender and **kwargs to handle all signal arguments flexibly.
  2. Step 2: Identify mismatch in receiver parameters

    The receiver only accepts sender and data, missing **kwargs, which causes errors when extra arguments are sent.
  3. Final Answer:

    The receiver function must accept **kwargs, not just named arguments -> Option A
  4. Quick Check:

    Receiver needs **kwargs for signal args [OK]
Quick Trick: Receiver functions always need **kwargs parameter [OK]
Common Mistakes:
MISTAKES
  • Forgetting **kwargs in receiver signature
  • Importing Signal from wrong module
  • Assuming connect requires sender argument
  • Confusing list and tuple for providing_args

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Django Quizzes