1

I have a viewset like the follwing

class DummyViewSet:
    def create(self, request, *args, **kwargs): 
        variable_a = 5
        return another_api_end_point(request, variable_a) ---> request.data: {"a":"value1", "b": "value2"}

@api_view(['POST'])
another_api_end_point(request, variable_a)
    print(request.data) ---> request.data: {} 
    print(variable_a) ---> variable_a: 5
    return "Some Response"

Why I can able to see variable_a's value as it is but request.data as empty in other endpoint?

Debugging it for hours now.

If anyone knows the reason for it, please revert. It would be a great help.

NEW VK
  • 15
  • 6
  • An `@api_view` processes the request, and you here thus process it a second time. – Willem Van Onsem Feb 04 '22 at 16:50
  • Please provide all the code necessary to represent a [minimal reproducible example](https://stackoverflow.com/help/minimal-reproducible-example). How are you calling `another_api_end_point`? How are you creating `DummyViewSet` objects? – ddejohn Feb 04 '22 at 16:50
  • @WillemVanOnsem you mean the second api overriding the request variable and making it empty? – NEW VK Feb 04 '22 at 17:15

1 Answers1

2

you can start with

request.__dict__

to see if the request is truly empty or you are just accessing it the wrong way. Given limited info, You can try the following to get the proper data given request.dict is not empty.

request.body()
request.json()