How to access user objects at the front end using Framework's TokenAuthentication
How to access user objects at the front end using Django Framework's TokenAuthentication. I was able to successfully get a token, which includes the user id and username of the user logged in but I am unsure of how to get the rest of the user information in the front end.
I am a beginner in programing, so your help is much appreciated.
- There are too many ways to do that - or simply you can retrieve user info from user model by using user_id and return it as a json in response context.
from rest_framework import response, status
def user_info(request)
user_ins = User.objects.get(id=request.user.id)
context = {
"user_info": {
"first_name": user_ins.first_name,
"last_name": user_ins.last_name,
"username": user_ins.username,
"email": user_ins.email
}
return response.Response(status=status.HTTP_200_OK, data=context)