S
S
Salavat Sharapov2014-12-02 22:34:12
Django
Salavat Sharapov, 2014-12-02 22:34:12

How to use response in signal?

Kind!
I can't figure out how to use the response from send.
The docs say:

Both send() and send_robust() return a list of tuple pairs [(receiver, response), ... ], representing the list of called receiver functions and their response values.

Example:
signals.py
from django.dispatch import Signal

requested = Signal(providing_args=["request"])

veiws.py
from signals import requested

def foo (request):
     ....
     requested.send(sender=None, request=request)

handlers.py
from django.dispatch import receiver
from signals import requested

@receiver(requested)
def foo1(sender, **kwargs):
      request = kwargs['request']
      ###Как тут вернуть response?

Or did I just write nonsense 0_o

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vladislav, 2014-12-02
@RGV

The debugger and prints can help you understand what request is
request = [(receiver, response), ... ]
response = request[0][1]

A
Anatoly Scherbakov, 2014-12-03
@Altaisoft

Hmm... what if we just write return "bar"in a function that catches a signal?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question