shaare.it

AttributeError: request.user has no attribute 'profile'

7 Dec 2025

1 min read

AttributeError: user.profile missing

$ python - <<'PY'
class U: pass
u=U()
try:
    print(u.profile)
except Exception as e:
    print(type(e).__name__, e)
PY
AttributeError 'U' object has no attribute 'profile'

Why this happens

One-to-one related Profile doesn’t exist yet.

Fix

Create on signup via signals or use get_or_create.

Wrong code

request.user.profile.bio

Fixed code

profile, _ = Profile.objects.get_or_create(user=request.user)
profile.bio