Reputation: 401
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:-
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??
Upvotes: 2
Views: 609
Reputation: 956
You could change or set the URL_FIELD_NAME
to None
which is used for setting the Location header:
REST_FRAMEWORK = {
"URL_FIELD_NAME": None, # This field is used in the Location header on a created resource
}
Upvotes: 0
Reputation: 1117
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 {}
Upvotes: 1