如何挂接django-allauth信号? [英] How do I hook a django-allauth signal?

查看:54
本文介绍了如何挂接django-allauth信号?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

我正在尝试挂起email_verified信号:

I am trying to hook the email_verified signal:

allauth.account.signals.email_confirmed(请求,电子邮件地址)

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

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.

这是我的apps.py代码:

here is my apps.py code:

from django.apps import AppConfig

class EngineConfig(AppConfig):
    name = 'engine'

    def ready(self):
        import engine.signals

推荐答案

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

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

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

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

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

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)

这篇关于如何挂接django-allauth信号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆