How do I hook a django-allauth signal?

情到浓时终转凉″ 提交于 2021-01-28 05:08:24

问题


Signals page for django-allauth: https://django-allauth.readthedocs.io/en/latest/signals.html

I am trying to hook the email_verified signal:

allauth.account.signals.email_confirmed(request, email_address)

And am getting nothing whenever a user confirms their email. Here is my code:

from allauth.account.signals import email_confirmed
from channels import Group

def send_to_user_socket(sender, **kwargs):
    Group('%s.get-started' % (kwargs['request'].user.username)).send({'text': json.dumps({'message': 'Email confirmed'})})

email_confirmed.connect(send_to_user_socket)

What am I doing wrong? Thanks in advance.

Edit: here is my apps.py code:

from django.apps import AppConfig

class EngineConfig(AppConfig):
    name = 'engine'

    def ready(self):
        import engine.signals

回答1:


I had a similar issue, but it was resolved by doing the following

In your init.py file within the particular app, add

default_app_config = "{enter_you_app_name}.apps.{Appname}Config"

eg

default_app_config = "authentication.apps.AuthenticationConfig"

also import

from django.dispatch import receiver

@reciever(enter_the_correct_details)
def send_to_user_socket(sender, **kwargs):
    Group('%s.get-started' % (kwargs['request'].user.username)).send({'text': json.dumps({'message': 'Email confirmed'})})

email_confirmed.connect(send_to_user_socket)


来源:https://stackoverflow.com/questions/51509224/how-do-i-hook-a-django-allauth-signal

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!