zbtong
zbtong

Reputation: 319

How to restrict User can only edit their profile in django?

I want the user can edit their own profile, but can't edit other user's, how to make this kind of restriction in Django?

@login_required
def edit_profile:
  # some check
  pass

Upvotes: 0

Views: 801

Answers (1)

catavaran
catavaran

Reputation: 45575

You don't need any restriction. Just get the profile of the logged user and edit it:

@login_required
def edit_profile(request):
    profile = request.user.profile
    ...

Upvotes: 4

Related Questions