首页 > 解决方案 > Allauth social_account_added 信号未发送

问题描述

视图.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并将其设置为 Provider 提供的图像。

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

非常感谢任何帮助。

谢谢

标签: djangodjango-allauth

解决方案


推荐阅读