3

I'm having problems with connecting to a signal in django. I've been following a tutorial available at http://dmitko.ru/?p=546 and tried to extend user registration.

I have django-registration correctly set up. It is working fine. For debug purpose I've put the following code into my urls.py:

from registration.signals import user_registered

def log_user_created(sender, user, request, ** kwargs):
  logger.debug("got USER_REGISTERED signal")

if settings.DEBUG:
  logger.debug("registering debug signal listeners")
  user_registered.connect(log_user_created)
else:
  logger.debug("debuging signals not enabled")    

However the log_user_created function is never called.

My question is: how can I debug my app to see where the user_registered signal is being swallowed?

Note: I've checked that my version of django-registration works correctly. I've switched my version with the one from the mentioned blog's example app. It did not change the observed behaviour.

Marcin Cylke
  • 2,100
  • 2
  • 21
  • 40
  • You can check the [following answer](http://stackoverflow.com/questions/40392042/why-does-the-signal-not-trigger/40400653#40400653). – Brkyrn Nov 04 '16 at 09:56

3 Answers3

6

Make sure that the code that connects to the signal and the code that sends signals both import the with the same path. For example, if you connect a signal with:

from myapp.registration.signals import user_registered
user_registered.connect(...)

Then later when you send this signal you must import it with

from myapp.registration.signals import user_registered

(notice the myapp.) and not:

from registration.signals import user_registered

otherwise they'll be treated as two different signals.

pseudosudo
  • 6,270
  • 9
  • 40
  • 53
0

Did you try to put user_registered.connect(user_created) in regbackend.py (and not in urls.py) as shown in the example you linked?

You can find some additional info on where to best connect your signals in this question.

To see if user_registered is called correctly you simply could add a debug call at the beginning of the user_created function.

django-debug-toolbar, though i haven't used that specific feature, might be another option:

Currently, the following panels have been written and are working:

  • List of signals, their args and receivers
Community
  • 1
  • 1
arie
  • 18,737
  • 5
  • 70
  • 76
  • The mentioned steps are what I've already done. Neither debug log at the beginning of my __user_registered__ function, nor placing it in regbackend.py helped. I've also used django-debug-toolbar, but it doesn't show the user_registered signal. Not in my app, and not in the working on, (http://dmitko.ru/?p=546) – Marcin Cylke May 16 '11 at 17:55
0

I created a sample application, that you can play with (I believe it works) http://dmitko.ru/samples/sample_user_registration.zip

dmitko
  • 2,607
  • 2
  • 21
  • 15
  • 1
    I've tried it, but as I've written in my question, it works great. I can't figure out how to debug my app. I'm pretty sure I did all the things that You did in your app (apparently I'm wrong as my app is not working ;-) ). I've included django-debug-toolbar but it does not show __user_registered__ signal, neither in my app nor in yours. Do you know how to debug the problem with sending the signals in django? – Marcin Cylke May 16 '11 at 21:34