0
0
Djangoframework~5 mins

Custom signals in Django - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is a custom signal in Django?
A custom signal is a way to send notifications within your Django app when certain actions happen. It lets different parts of your app talk to each other without being tightly connected.
Click to reveal answer
beginner
How do you create a custom signal in Django?
You create a custom signal by importing Signal from django.dispatch and then defining a new Signal instance, like my_signal = Signal().
Click to reveal answer
beginner
What is the role of a receiver function in Django signals?
A receiver function listens for a signal and runs some code when that signal is sent. It connects to the signal using the @receiver decorator or the connect() method.
Click to reveal answer
beginner
How do you send a custom signal in Django?
You send a custom signal by calling its send() method, usually passing the sender and any extra data as keyword arguments.
Click to reveal answer
intermediate
Why use custom signals instead of calling functions directly?
Custom signals help keep your code loosely connected. This means parts of your app can work independently and be easier to maintain or change later.
Click to reveal answer
Which Django module do you import to create a custom signal?
Adjango.signals
Bdjango.dispatch
Cdjango.utils
Ddjango.models
What decorator is commonly used to connect a receiver function to a signal?
A@receiver
B@signal
C@connect
D@listen
What method do you call to send a custom signal?
Asend()
Btrigger()
Cdispatch()
Demit()
Which argument is usually passed as the sender when sending a signal?
AThe signal instance
BThe receiver function
CThe class or object sending the signal
DThe Django app name
What is a key benefit of using custom signals in Django?
AMakes code run faster
BReplaces the need for views
CTightens code coupling
DAllows parts of code to communicate without direct calls
Explain how to create, connect, and send a custom signal in Django.
Think about the steps from defining the signal to making it work.
You got /5 concepts.
    Describe why using custom signals can improve your Django app's design.
    Consider how signals affect code connections.
    You got /4 concepts.