[Fixed]-Django – extend user profile error user has no attribute userprofile

2👍

✅

You need to get userprofile by attribute name, not the model name:

...
else:
    profile_form = ProfileForm(instance=request.user.userprofile)

This might help, also u can set related_name argument, when creating a field, so the attribute name will correspond to that name.

-1👍

Use primary_key of UserProfile class then it will work. Don’t use UserProfile class directly in request.user

profile_form = ProfileForm(instance=request.user.user_profile_primary_key)

Leave a comment