0
0
Djangoframework~10 mins

Why signals enable decoupled communication in Django - Test Your Understanding

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to import the Django signal dispatcher.

Django
from django.dispatch import [1]
Drag options to blanks, or click blank then click option'
Areceiver
BSignal
Cconnect
Dsend
Attempts:
3 left
💡 Hint
Common Mistakes
Importing 'receiver' instead of 'Signal'.
Trying to import 'connect' which is a method, not a class.
2fill in blank
medium

Complete the code to define a new custom signal.

Django
my_signal = [1]()
Drag options to blanks, or click blank then click option'
ASignal
Bconnect
Creceiver
Dsend
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'receiver' which is a decorator, not a signal.
Using 'send' which is a method to send signals.
3fill in blank
hard

Fix 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'
Aconnect
Bsend
Cmy_signal
Dreceiver
Attempts:
3 left
💡 Hint
Common Mistakes
Passing 'send' or 'connect' which are methods, not signals.
Passing 'receiver' which is a decorator, not a signal.
4fill in blank
hard

Fill 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'
Asend
Bsend_robust
Cmyapp.models.MyModel
DNone
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'send_robust' when 'send' is enough here.
Using 'None' as sender when a class is expected.
5fill in blank
hard

Fill 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'
Areceiver
BSignal
Ckwargs
Dconnect
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.