Home > Software engineering >  rest_framework.response return string? python
rest_framework.response return string? python

Time:06-15

can you help me please?

I have the following code

from rest_framework.response import Response
......
return Response(data=str({'id': pk}), status=status.HTTP_403_FORBIDDEN, content_type='application/json')

Return "{'id': '54fa0000-1cdd-4c6d-83d7-ab19a7f11944'}"

How can I return without quotes at the beginning and at the end? {'id': '54fa0000-1cdd-4c6d-83d7-ab19a7f11944'}

CodePudding user response:

rest_framework's Response returns json by default, so:

return Response({'id': pk}, status=status.HTTP_403_FORBIDDEN)

CodePudding user response:

run it.

return Response({'id': pk}, status=status.HTTP_403_FORBIDDEN)

Response

{"id": "54fa0000-1cdd-4c6d-83d7-ab19a7f11944"}

but now it comes out with double quotes and I need it without double quotes example:

{'id': '54fa0000-1cdd-4c6d-83d7-ab19a7f11944'}
  • Related