我尝试在激活时(而不是在创建用户时)保存用户配置文件,但监听器不会调用 create_user_profile()。监听器位于 models.py 中。
from registration.signals import user_activated
from mysite.signals import create_user_profile
user_activated.connect(create_user_profile, sender=User)
我正在使用 django-registration-redux。我没有覆盖注册过程中的任何内容。在 registration/signals.py 中,信号为:
user_activated = Signal(providing_args=["user", "request"])
在registration/default/views.py中有这个函数:
def activate(self, request, activation_key):
"""
Given an an activation key, look up and activate the user
account corresponding to that key (if possible).
After successful activation, the signal
``registration.signals.user_activated`` will be sent, with the
newly activated ``User`` as the keyword argument ``user`` and
the class of this backend as the sender.
"""
activated_user = RegistrationProfile.objects.activate_user(activation_key)
if activated_user:
signals.user_activated.send(sender=self.__class__,
user=activated_user,
request=request)
在 PyCharm 中,我在调用 send() 的最后一行放置了一个断点。当用户被激活时,执行会在该断点处暂停,然后从那里继续执行,不会出现错误消息。就好像听众根本不存在一样。
最佳答案
发送者可能应该是 User
类:
signals.user_activated.send(sender=activated_user.__class__,
user=activated_user,
request=request)
关于python - Django 监听器听不到信号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27885464/