Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to import the Django signal dispatcher.
Django
from django.dispatch import [1]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Importing 'receiver' instead of 'Signal'.
Trying to import 'connect' which is a method, not a class.
✗ Incorrect
The Signal class is imported from django.dispatch to create custom signals.
2fill in blank
mediumComplete the code to define a new custom signal.
Django
my_signal = [1]() Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'receiver' which is a decorator, not a signal.
Using 'send' which is a method to send signals.
✗ Incorrect
To define a new signal, you create an instance of the Signal class.
3fill in blank
hardFix the error in connecting a receiver function to a signal.
Django
@receiver([1]) def my_handler(sender, **kwargs): print('Signal received')
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Passing 'send' or 'connect' which are methods, not signals.
Passing 'receiver' which is a decorator, not a signal.
✗ Incorrect
The @receiver decorator needs the signal instance to connect the handler properly.
4fill in blank
hardFill both blanks to send a signal with a sender and extra data.
Django
my_signal.[1](sender=[2], data='hello')
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'send_robust' when 'send' is enough here.
Using 'None' as sender when a class is expected.
✗ Incorrect
Use the send method on the signal instance, specifying the sender class.
5fill in blank
hardFill all three blanks to create a decoupled receiver function for a signal.
Django
from django.dispatch import [1] @[2](my_signal) def handle_signal(sender, **[3]): print('Handled decoupled signal')
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Importing 'Signal' instead of 'receiver'.
Using 'connect' as a decorator which is incorrect.
Not accepting '**kwargs' in the handler function.
✗ Incorrect
Import the receiver decorator, use it to decorate the handler, and accept kwargs for extra data.