查看allauth.account.signals.user_signed_up
信号,该信号在用户(社交或普通用户)注册后触发。你可以在那里用你的账户做你的事情:
from django.dispatch import receiver
from allauth.account.signals import user_signed_up
@receiver(user_signed_up)
def do_stuff_after_sign_up(sender, **kwargs):
request = kwargs['request']
user = kwargs['user']
# Do your stuff with the user
user.save()
来自django-allauth 回购:
# Typically followed by `user_logged_in` (unless, e-mail verification kicks in)
user_signed_up = Signal(providing_args=["request", "user"])
要了解如何在 django 中使用信号,请阅读有关它的官方文档。
我希望它对你有帮助!
编辑
我很高兴您找到了解决问题的方法,但是由于始终加载中间件,我建议使用我提出的方法。该socialaccount
模块django-allauth
还提供信号。其中,您可以找到allauth.socialaccount.signals.social_account_added
:
# Sent after a user connects a social account to a his local account.
social_account_added = Signal(providing_args=["request", "sociallogin"])
使用与之前编写的类似的处理程序,您可以检查用户模型的必填字段,然后调用重定向快捷方式,或返回重定向到显示/处理表单的视图的HttpResponseRedirect对象。