Issue
In my app I am trying to get the User data using a get request and it works in Postman but the problem occurs when I try to send the data from FrontEnd as we cannot send Body
in get
Request
URL:
path('user/meta/', UserDetails.as_view()),
Views.py
class UserDetails(APIView):
"""Get basic details of user"""
def get(self, request):
username = request.data["username"]
if User.objects.filter(username = username).exists():
user = User.objects.get(username = username)
print(user)
return Response({
'verified': user.verified,
})
else:
return Response("User doesn't exists", status=status.HTTP_400_BAD_REQUEST)
How should I modify it such that I can get the data from get
request?
Solution
So, your requesting URL will become
/user-info/?username=john
and then, use request.GET
username = request.GET.get("username","default_value")
Answered By - JPG
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.