RelatedObjectDoesNotExist: User has no userprofile

后端 未结 7 1067
旧巷少年郎
旧巷少年郎 2020-12-28 17:58

So I\'ve extended my user with the field score like this:

models.py:

class UserProfile(models.Model):
    user = models.OneToOneField(Us         


        
7条回答
  •  一生所求
    2020-12-28 18:33

    I'm a bit kinda late for this but ill just, share the solution that worked for me on Django 3.0.8...

    Error : RelatedObjectDoesNotExist: User has no profile

    This the is where my error was directing me to :

    @login_required
    def dashboard(request):
        if request.method == 'POST':
            user_form = UserEditForm(instance=request.user, data=request.POST)
            profile_form = ProfileEditForm(instance=request.user.profile, data=request.POST, files=request.FILES)
    

    Note: You have to login or your profile to be saved.

    Just after creating your account, you should be able to see that you are not logged in and you will have to log in to for your profile be saved and to start working.

提交回复
热议问题