Hi Folks,
class LocationApiView(APIView):
permission_classes = (IsAuthenticated,)
def get(self,request,format=None):
user = request.user
user_location = Profile.objects.get(user = user)
return Response({'user':user}, status = status.HTTP_200_OK)
-- I'm getting this error, I don't know how to solve it:
File "C:\Users\TildeHat\AppData\Local\Programs\Python\Python38-32\lib\json\encoder.py", line 179, in default
raise TypeError(f'Object of type {o.__class__.__name__} '
TypeError: Object of type User is not JSON serializable
raise TypeError(f'Object of type {o.__class__.__name__} '
TypeError: Object of type User is not JSON serializable
This is my code:
Views.py:
--------------
class LocationApiView(APIView):
permission_classes = (IsAuthenticated,)
def get(self,request,format=None):
user = request.user
user_location = Profile.objects.get(user = user)
return Response({'user':user}, status = status.HTTP_200_OK)
urls.py
----------------
urlpatterns = [
path('api/location/',views.LocationApiView.as_view(),name = 'api_location')
]
path('api/location/',views.LocationApiView.as_view(),name = 'api_location')
]
btw when I'm sending a normal message it's working fine. But in this case I'm getting this error.
Thank You
Regards,
Soumen
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAPUw6WZh%2BgVfi7URo8vPbpjYfT%3D5AdjGyhntBMLgiZ1msiZECg%40mail.gmail.com.
No comments:
Post a Comment