[Django]-Django Rest framework: passing request object around makes it lose POST data in newer version

8👍

You could just separate out the logic you’re storing in the build view into a common function used by both endpoints without any decorators e.g. _build – this way whatever is happening within the decorators shouldn’t occur in the case of the call within preview.

@csrf_protect
@api_view(['POST'])
@authentication_classes((SessionAuthentication,))
def preview(request, project_id, channel_type, format=None):        
    return _build(request, project_id, channel_type, preview=True, format=format)

@csrf_protect
@api_view(['POST'])
@authentication_classes((SessionAuthentication,))
def build(request, project_id, channel_type, preview=True, builder=None, build_after=True, format=None):
    return _build(request, project_id, channel_type, preview=preview, builder=builder, build_after=build_after, format=format)


def _build(request, project_id, channel_type, preview=True, builder=None, build_after=True, format=None):
    pass

Leave a comment