如何挂接django-allauth信号?

时间:2018-07-25 00:18:19

标签: django signals django-allauth

django-allauth的信号页面:https://django-allauth.readthedocs.io/en/latest/signals.html

我正在尝试挂起email_verified信号:

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

每当用户确认电子邮件时,他们什么也没收到。这是我的代码:

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)

我在做什么错?预先感谢。

编辑:这是我的apps.py代码:

from django.apps import AppConfig

class EngineConfig(AppConfig):
    name = 'engine'

    def ready(self):
        import engine.signals

1 个答案:

答案 0 :(得分:0)

我遇到了类似的问题,但是通过执行以下操作已解决了

在特定应用程序的 init .py文件中,添加

default_app_config =“ {enter_you_app_name} .apps。{Appname} Config”

例如

default_app_config = "authentication.apps.AuthenticationConfig"

也可以导入

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)