How to remove `LOCATION` from the header options in DRF?

Viewed 186

I have a serializer which contains a URL field, By default, if there is a field named as URL then the value of this field is added in the HEADER option as LOCATION, I don't want to do this, and would like to remove the LOCATION option from the header.

This is my serializer:-

class DemoSerializer(serializers.ModelSerializer):
    class Meta:
        model = Demo
        fields = ('type', 'protocol', ---- 'url', 'somefield')

Now when the above serializer is used with POST/PUT/PATCH request to send data, I get this as response:- enter image description here

Is there any method, or way I can remove the LOCATION option from the header, without effecting my other serializers and view in the project??

1 Answers

In View which is you want to remove Location header, you should override get_success_headers function.

Default

    def get_success_headers(self, data):
        try:
            return {'Location': str(data[api_settings.URL_FIELD_NAME])}
        except (TypeError, KeyError):
            return {}

Override

    def get_success_headers(self, data):
        return {}
Related