1👍
✅
You can make use of @action
decorator.
Give this a try:
class UserAPI(viewsets.ModelViewSet):
...
@action(detail=False)
def profile(self, request):
serializer = UserSerializer(request.user)
return Response(serializer.data)
Now go to 127.0.0.1:8000/users/profile/, you should see the current authenticated user’s data.
0👍
this may be helpful.
You can use user = request.user.id
, by in this way you can get current login user.
- [Answered ]-Access django channels' consumer class variables from outside
- [Answered ]-Django (1.6) custom user model
- [Answered ]-Django admin site
- [Answered ]-A linear gradient with variable number of stops in LESS? (or Sass)
- [Answered ]-Django: My context variable cannot be used for duplicate for loops
Source:stackexchange.com