0
0
Djangoframework~5 mins

Receiver decorator in Django - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is the purpose of the @receiver decorator in Django?
The @receiver decorator connects a function to a Django signal, so the function runs automatically when that signal is sent.
Click to reveal answer
beginner
How do you import the <code>@receiver</code> decorator in Django?
You import it with: <code>from django.dispatch import receiver</code>.
Click to reveal answer
intermediate
Explain the role of the signal argument in the @receiver(signal) decorator.
The signal argument tells Django which signal the decorated function should listen to and respond when that signal is sent.
Click to reveal answer
intermediate
What parameters does a receiver function typically accept?
A receiver function usually accepts sender, instance, and **kwargs to get details about the signal event.
Click to reveal answer
intermediate
Why is using the @receiver decorator better than manually connecting signals with signal.connect()?
The @receiver decorator makes the code cleaner and easier to read by linking the function directly to the signal in one place.
Click to reveal answer
What does the @receiver decorator do in Django?
ARuns a function immediately
BCreates a new signal
CDeletes a signal
DConnects a function to a signal
Which module do you import @receiver from?
Adjango.models
Bdjango.signals
Cdjango.dispatch
Ddjango.utils
What argument do you pass to the @receiver decorator?
AThe signal to listen for
BThe sender class
CThe function name
DThe model name
Which of these is NOT a typical parameter of a receiver function?
Arequest
Binstance
Csender
D**kwargs
Why use the @receiver decorator instead of signal.connect()?
AIt runs the function faster
BIt makes code cleaner and easier to read
CIt disables the signal
DIt automatically deletes the function
Describe how the @receiver decorator works in Django and why it is useful.
Think about how Django signals notify parts of your app and how the decorator helps handle that.
You got /4 concepts.
    Explain the typical parameters a receiver function accepts and what information they provide.
    Consider what details the function needs to respond properly to the signal.
    You got /3 concepts.