Skip to content Skip to sidebar Skip to footer

Django Extending User With Userprofile (error: User Has No Profile.)

someone can told me, why this code don't working? I'm trying to create a registration form for users. I'm getting an error 'RelatedObjectDoesNotExist at /signup/client/2/ User has

Solution 1:

You need to create a profile, it does not get created when you save user_form

        user_form = UserCreationForm(request.POST)
        profile_form = ProfileForm(request.POST)
        if user_form.is_valid() and profile_form.is_valid():
            user = user_form.save()
            Profile.objects.create(**{
                 'city':"WW", 'phone': '32323', 'user': user
            })
            # ^^^^^^

Solution 2:

You should add the following line to the script:

profile = Profile.objects.create(user=request.user)

Solution 3:

I believe this code is referred from 'Django by Examples'. If so, Go to your application admin Site and add a profile manually under profile account and run the server again. This will solve the issue.

Solution 4:

The best and easiest thing to do here while in the development is:

  1. in the terminal create another superuser -$ python manage.py createsuperuser
  2. login in the admin page with the new credentials
  3. Delete the old admin or any user that may have been created before the userprofile models were created

Post a Comment for "Django Extending User With Userprofile (error: User Has No Profile.)"