django-registration and user profile creation

后端 未结 2 735
说谎
说谎 2021-01-31 13:10

In my app i have the AUTH_PROFILE_MODULE set to users.UserProfile. This UserProfile has a function create which should be called, when a n

2条回答
  •  孤独总比滥情好
    2021-01-31 13:14

    Django-registration provides two signals, which are:

    • user_registered : Sent when registration is complete
    • user_activated : Sent when user has activated his account using the activation link

    For your case, you need user_registered

    from registration.signals import user_registered
    def createUserProfile(sender, instance, **kwargs):
        user_profile = UserProfile.objects.create(user=instance)
    
    user_registered.connect(createUserProfile)
    

    You don't need to create any separate signals.py file. You can keep this code in models.py of any of your app. However, since its Profile creation code, you should keep it in profiles/models.py

提交回复
热议问题