Try from django.http import JsonResponse And use jsonresponse instead
Le jeu. 20 févr. 2020 17:59, Soumen Khatua <[email protected]> a écrit : > If I'm using serializer then it's working fine but I want to return only > database object. So for that Do I need to add serializer. > > Thank you for your response. > > On Thu 20 Feb, 2020, 11:17 PM MTS BOUR, <[email protected]> wrote: > >> Can you show us your serializer.py file? >> >> >> Le jeu. 20 févr. 2020 17:40, Soumen Khatua <[email protected]> a >> écrit : >> >>> Hi Folks, >>> >>> 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* >>> >>> >>> *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')]* >>> >>> >>> *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 [email protected]. >>> To view this discussion on the web visit >>> https://groups.google.com/d/msgid/django-users/CAPUw6WZh%2BgVfi7URo8vPbpjYfT%3D5AdjGyhntBMLgiZ1msiZECg%40mail.gmail.com >>> <https://groups.google.com/d/msgid/django-users/CAPUw6WZh%2BgVfi7URo8vPbpjYfT%3D5AdjGyhntBMLgiZ1msiZECg%40mail.gmail.com?utm_medium=email&utm_source=footer> >>> . >>> >> -- >> 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 [email protected]. >> To view this discussion on the web visit >> https://groups.google.com/d/msgid/django-users/CAAq3G-Ea6aEgo9ECrkbe2Y0bXWGG-GVb-utLf%2B7bn9RCGZ0fGw%40mail.gmail.com >> <https://groups.google.com/d/msgid/django-users/CAAq3G-Ea6aEgo9ECrkbe2Y0bXWGG-GVb-utLf%2B7bn9RCGZ0fGw%40mail.gmail.com?utm_medium=email&utm_source=footer> >> . >> > -- > 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 [email protected]. > To view this discussion on the web visit > https://groups.google.com/d/msgid/django-users/CAPUw6WbZ%2BOYqcEpadaxCz_9z45dDpbLRduLuUsgGAg2DyPnhFQ%40mail.gmail.com > <https://groups.google.com/d/msgid/django-users/CAPUw6WbZ%2BOYqcEpadaxCz_9z45dDpbLRduLuUsgGAg2DyPnhFQ%40mail.gmail.com?utm_medium=email&utm_source=footer> > . > -- 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 [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAAq3G-FOCi7bGJ8ebBG3WnJcqOtiJCFSxmds4jm4hyxxaG9Svg%40mail.gmail.com.

