微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Allauth social_account_ added 信号未发送

如何解决Allauth social_account_ added 信号未发送

views.py


@receiver(post_save,sender=User)
def create_profile(sender,instance,created,**kwargs):
    if created:
        Profile.objects.create(user=instance)

@receiver(social_account_added)
def after_social_account_added(request,sociallogin,**kwargs):
    profile = Profile.objects.filter(user=request.user).first()
    sc = sociallogin.account

    if DEFAULT_PP in profile.avatar.url:
        if sc.provider == 'facebook':
            profile.avatar = f"http://graph.facebook.com/{sociallogin.account.uid}/picture"
        else:
            profile.avatar = sc.extra_data[ALL_AUTH_IMAGE_KEYS[sc.provider]]
    profile.save()

create_profile 在创建用户时被触发,它会创建一个新的 Profile

用户添加他们的社交帐户时,after_social_account_added 会被触发,它会更新 Profile 的头像并将其设置为提供者提供的图像。

create_profile 工作正常,但 after_social_account_added 不运行。

非常感谢任何帮助。

谢谢

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。