1👍
✅
There is no need to implement a slug_field
or anything if you only want to show this to the owner. You can simply return the logged in use in get_object
:
class UserDetailView(LoginRequiredMixin, DetailView):
model = User
def get_object(self, *args, **kwargs):
return self.request.user
The url can thus look like:
path('profile/', UserDetailView.as_view(), name='profile')
without a primary key, since the User
object is fully determined by the logged in user.
Source:stackexchange.com