[Fixed]-DRF – access request's POST data

1πŸ‘

I believe you should be able to override the initial() method on your view in order to achieve what you’re attempting. The docstring from the APIView class reads:

"""
Runs anything that needs to occur prior to calling the method handler.
"""

So, it would look something like:

class FaveoAPIView(APIView):

    def initial(self, request, *args, **kwargs):
        super(FaveoAPIView, self).initial(request, *args, **kwargs)
        # Manipulate request.data to your heart's content here

In APIView, this is called immediately before your method handler.

πŸ‘€Joey Wilhelm

0πŸ‘

super(FaveoAPIView, self).dispatch(request, *args, **kwargs) will call initialize_request turning the request into a DRF one. This can only be once therefore it’ll fail after that.

Instead of fixing a broken solution, could you rather tell us about your actual issue, i.e. why you need to access the requests data before the view itself is called ?

πŸ‘€Linovia

Leave a comment