Skip to content Skip to sidebar Skip to footer

Django - Extended User Profile, Object Does Not Exist, How To Create A Blank Record?

ive created a user profile class as per below, if the user clicks on the my account page and they dont have a record i get the below error: RelatedObjectDoesNotExist at /profile Us

Solution 1:

I'd recommend doing the following two things:

  1. Create a Data migration that creates a blank user profile for all existing users Django Migrations Documentation
  2. Create a post_save signal handler for User to automatically create a profile object when a new user is created Django Signals

Solution 2:

You have to check first user exists or not

@login_required@transaction.atomic
def update_profile(request):
    if request.method == 'POST':
        if request.user.userprofile is None:
            user_profile = UserProfile(user=request.user)
            user_profile.save
        ...

Post a Comment for "Django - Extended User Profile, Object Does Not Exist, How To Create A Blank Record?"