Django REST framework, content negotiationDoes Django scale?Django REST framework: non-model serializerAndroid HttpPut to Django REST Framework - data not updatingdjango rest framework SerializerMethodField bizarre behaviourWhere to alter the response of POST request in Django REST FrameworkDjango: TemplateDoesNotExist (rest_framework/api.html)Why dispatch method is taking long time to call target method in Django Rest Framework?Return NoneType on queryset django REST frameworkDjango Rest Framework doesn't render generics.ListAPIView, model with GM2MFieldDjango Rest Framework: serializer response error
Are there categories whose internal hom is somewhat 'exotic'?
Does git delete empty folders?
The Lucky House
Polar contour plot in Mathematica?
Check disk usage of files returned with spaces
Atmospheric methane to carbon
Best model for precedence constraints within scheduling problem
Is recepted a word?
Inset Square From a Rectangular Face
Do predators tend to have vertical slit pupils versus horizontal for prey animals?
My father gets angry everytime I pass Salam, that means I should stop saying Salam when he's around?
Reducing contention in thread-safe LruCache
Can 'in-' mean both 'in' and 'no'?
Why doesn't mathematics collapse down, even though humans quite often make mistakes in their proofs?
Did Wernher von Braun really have a "Saturn V painted as the V2"?
My new Acer Aspire 7 doesn't have a Legacy Boot option, what can I do to get it?
Meaning and structure of headline "Hair it is: A List of ..."
How to detect a failed AES256 decryption programmatically?
Why did St. Jerome use "virago" in Gen. 2:23?
Build a mob of suspiciously happy lenny faces ( ͡° ͜ʖ ͡°)
Is there a way to make the "o" keypress of other-window <C-x><C-o> repeatable?
Starships without computers?
Are unaudited server logs admissible in a court of law?
What can I do to keep a threaded bolt from falling out of it’s slot
Django REST framework, content negotiation
Does Django scale?Django REST framework: non-model serializerAndroid HttpPut to Django REST Framework - data not updatingdjango rest framework SerializerMethodField bizarre behaviourWhere to alter the response of POST request in Django REST FrameworkDjango: TemplateDoesNotExist (rest_framework/api.html)Why dispatch method is taking long time to call target method in Django Rest Framework?Return NoneType on queryset django REST frameworkDjango Rest Framework doesn't render generics.ListAPIView, model with GM2MFieldDjango Rest Framework: serializer response error
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I am trying to get my endpoint to return a uri-list
when asked for that and a json string as default. I am testing this in a unit test looking a bit like:
[...]
headers = 'Accept': 'text/uri-list'
response = self.client.get('/api/v1/licenses/', headers=headers)
[...]
I have written a URIListRenderer
like this:
from rest_framework import renderers
class URIListRenderer(renderers.BaseRenderer):
media_type = 'text/uri-list'
def render(self, data, media_type='None', renderer_context=None):
return "n".join(data).encode()
Next I am trying to get my Response in my View to be rendered using my renderer:
class RestLicenses(APIView):
"""
List all licenses, or create a new license
"""
permission_classes = (IsAuthenticated,)
parser_classes = (MultiPartParser,)
renderer_classes = (JSONRenderer, URIListRenderer,)
def get(self, request, format=None,):
models = LicenseModel.objects.all()
if len(models) == 0 :
return Response('[]',status=204)
if request.META.get('headers') is not None :
if request.META.get('headers').get('Accept') == 'text/uri-list' :
result = [];
for m in models :
result.append(reverse('downloadLicense', args=[m.pk], request=request))
return Response(result, status=200)
serializer = LicenseJSONSerializer(request, models, many=True)
serializer.is_valid()
return HttpResponse(JSONRenderer().render(serializer.data), content_type='application/json', status=200)
But it seems impossible to get it to choose any other renderer than the first one in the list. How do I make it choose my URIListRenderer
and not the json one?
django django-rest-framework
add a comment |
I am trying to get my endpoint to return a uri-list
when asked for that and a json string as default. I am testing this in a unit test looking a bit like:
[...]
headers = 'Accept': 'text/uri-list'
response = self.client.get('/api/v1/licenses/', headers=headers)
[...]
I have written a URIListRenderer
like this:
from rest_framework import renderers
class URIListRenderer(renderers.BaseRenderer):
media_type = 'text/uri-list'
def render(self, data, media_type='None', renderer_context=None):
return "n".join(data).encode()
Next I am trying to get my Response in my View to be rendered using my renderer:
class RestLicenses(APIView):
"""
List all licenses, or create a new license
"""
permission_classes = (IsAuthenticated,)
parser_classes = (MultiPartParser,)
renderer_classes = (JSONRenderer, URIListRenderer,)
def get(self, request, format=None,):
models = LicenseModel.objects.all()
if len(models) == 0 :
return Response('[]',status=204)
if request.META.get('headers') is not None :
if request.META.get('headers').get('Accept') == 'text/uri-list' :
result = [];
for m in models :
result.append(reverse('downloadLicense', args=[m.pk], request=request))
return Response(result, status=200)
serializer = LicenseJSONSerializer(request, models, many=True)
serializer.is_valid()
return HttpResponse(JSONRenderer().render(serializer.data), content_type='application/json', status=200)
But it seems impossible to get it to choose any other renderer than the first one in the list. How do I make it choose my URIListRenderer
and not the json one?
django django-rest-framework
Have you debugged whatrequest.META.get('headers').get('Accept')
actually returns?==
is a rather strict comparison type as strings go.
– Endre Both
Mar 27 at 14:11
It returns true, but it seems that the actual content negotiation takes place some completely different location and it always ends up with it picking the first renderer class.
– jonalv
Mar 27 at 14:54
Does the request have?format=json
as query parameter by any chance?
– dirkgroten
Mar 27 at 17:24
add a comment |
I am trying to get my endpoint to return a uri-list
when asked for that and a json string as default. I am testing this in a unit test looking a bit like:
[...]
headers = 'Accept': 'text/uri-list'
response = self.client.get('/api/v1/licenses/', headers=headers)
[...]
I have written a URIListRenderer
like this:
from rest_framework import renderers
class URIListRenderer(renderers.BaseRenderer):
media_type = 'text/uri-list'
def render(self, data, media_type='None', renderer_context=None):
return "n".join(data).encode()
Next I am trying to get my Response in my View to be rendered using my renderer:
class RestLicenses(APIView):
"""
List all licenses, or create a new license
"""
permission_classes = (IsAuthenticated,)
parser_classes = (MultiPartParser,)
renderer_classes = (JSONRenderer, URIListRenderer,)
def get(self, request, format=None,):
models = LicenseModel.objects.all()
if len(models) == 0 :
return Response('[]',status=204)
if request.META.get('headers') is not None :
if request.META.get('headers').get('Accept') == 'text/uri-list' :
result = [];
for m in models :
result.append(reverse('downloadLicense', args=[m.pk], request=request))
return Response(result, status=200)
serializer = LicenseJSONSerializer(request, models, many=True)
serializer.is_valid()
return HttpResponse(JSONRenderer().render(serializer.data), content_type='application/json', status=200)
But it seems impossible to get it to choose any other renderer than the first one in the list. How do I make it choose my URIListRenderer
and not the json one?
django django-rest-framework
I am trying to get my endpoint to return a uri-list
when asked for that and a json string as default. I am testing this in a unit test looking a bit like:
[...]
headers = 'Accept': 'text/uri-list'
response = self.client.get('/api/v1/licenses/', headers=headers)
[...]
I have written a URIListRenderer
like this:
from rest_framework import renderers
class URIListRenderer(renderers.BaseRenderer):
media_type = 'text/uri-list'
def render(self, data, media_type='None', renderer_context=None):
return "n".join(data).encode()
Next I am trying to get my Response in my View to be rendered using my renderer:
class RestLicenses(APIView):
"""
List all licenses, or create a new license
"""
permission_classes = (IsAuthenticated,)
parser_classes = (MultiPartParser,)
renderer_classes = (JSONRenderer, URIListRenderer,)
def get(self, request, format=None,):
models = LicenseModel.objects.all()
if len(models) == 0 :
return Response('[]',status=204)
if request.META.get('headers') is not None :
if request.META.get('headers').get('Accept') == 'text/uri-list' :
result = [];
for m in models :
result.append(reverse('downloadLicense', args=[m.pk], request=request))
return Response(result, status=200)
serializer = LicenseJSONSerializer(request, models, many=True)
serializer.is_valid()
return HttpResponse(JSONRenderer().render(serializer.data), content_type='application/json', status=200)
But it seems impossible to get it to choose any other renderer than the first one in the list. How do I make it choose my URIListRenderer
and not the json one?
django django-rest-framework
django django-rest-framework
asked Mar 27 at 13:51
jonalvjonalv
1,2805 gold badges24 silver badges51 bronze badges
1,2805 gold badges24 silver badges51 bronze badges
Have you debugged whatrequest.META.get('headers').get('Accept')
actually returns?==
is a rather strict comparison type as strings go.
– Endre Both
Mar 27 at 14:11
It returns true, but it seems that the actual content negotiation takes place some completely different location and it always ends up with it picking the first renderer class.
– jonalv
Mar 27 at 14:54
Does the request have?format=json
as query parameter by any chance?
– dirkgroten
Mar 27 at 17:24
add a comment |
Have you debugged whatrequest.META.get('headers').get('Accept')
actually returns?==
is a rather strict comparison type as strings go.
– Endre Both
Mar 27 at 14:11
It returns true, but it seems that the actual content negotiation takes place some completely different location and it always ends up with it picking the first renderer class.
– jonalv
Mar 27 at 14:54
Does the request have?format=json
as query parameter by any chance?
– dirkgroten
Mar 27 at 17:24
Have you debugged what
request.META.get('headers').get('Accept')
actually returns? ==
is a rather strict comparison type as strings go.– Endre Both
Mar 27 at 14:11
Have you debugged what
request.META.get('headers').get('Accept')
actually returns? ==
is a rather strict comparison type as strings go.– Endre Both
Mar 27 at 14:11
It returns true, but it seems that the actual content negotiation takes place some completely different location and it always ends up with it picking the first renderer class.
– jonalv
Mar 27 at 14:54
It returns true, but it seems that the actual content negotiation takes place some completely different location and it always ends up with it picking the first renderer class.
– jonalv
Mar 27 at 14:54
Does the request have
?format=json
as query parameter by any chance?– dirkgroten
Mar 27 at 17:24
Does the request have
?format=json
as query parameter by any chance?– dirkgroten
Mar 27 at 17:24
add a comment |
2 Answers
2
active
oldest
votes
Your unit test is not setting the headers correctly. As described here, you should use CGI style headers when using the Django test client:
response = self.client.get('/api/v1/licenses/', HTTP_ACCEPT='text/uri-list')
The content negotiation uses the real HTTP Accept header. In your code, you check that "headers" is set, but that's not the real HTTP Accept header. It should be:
if request.META.get('HTTP_ACCEPT') == "text/uri-list":
...
Exactly! after checking how the renderers are matched, I also concluded the header is not coming in correctly but I totally missed that part where he isn't setting it correctly in the test
– Ken4scholars
Mar 27 at 17:33
add a comment |
This is a block of code from the method finalize_response
:
if isinstance(response, Response):
if not getattr(request, 'accepted_renderer', None):
neg = self.perform_content_negotiation(request, force=True)
request.accepted_renderer, request.accepted_media_type = neg
response.accepted_renderer = request.accepted_renderer
response.accepted_media_type = request.accepted_media_type
response.renderer_context = self.get_renderer_context()
As you can see, before it performs content negotiaton, it checks to see if the view has already set the renderer needed and if not tries to perform the negotiation by itself.
So you can do this in your get method:
if request.META.get('headers') is not None :
if request.META.get('headers').get('Accept') == 'text/uri-list' :
request.accepted_renderer = URIListRenderer
result = [];
for m in models :
result.append(reverse('downloadLicense', args=[m.pk], request=request))
return Response(result, status=200)
Another thing you should probably do is to place your custom renderer class before JSONRenderer
in the renderer_classes list. In that way, it will first check the special case before the more general case during content negotiation. Is suspect that the request format also matches JSOnRender and it overshadows the custom renderer. Hope this helps
This shouldn't be needed. Setting theaccepted_renderer
will work, but why it's not matched using the default negotiation is strange. TheJSONRenderer
has only "application/json" as media type, so it shouldn't catch that one. Also you should set theaccepted_renderer
after the secondif
condition.
– dirkgroten
Mar 27 at 17:21
@dirkgroten yeah, I have fixed it.
– Ken4scholars
Mar 27 at 17:31
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55378895%2fdjango-rest-framework-content-negotiation%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
Your unit test is not setting the headers correctly. As described here, you should use CGI style headers when using the Django test client:
response = self.client.get('/api/v1/licenses/', HTTP_ACCEPT='text/uri-list')
The content negotiation uses the real HTTP Accept header. In your code, you check that "headers" is set, but that's not the real HTTP Accept header. It should be:
if request.META.get('HTTP_ACCEPT') == "text/uri-list":
...
Exactly! after checking how the renderers are matched, I also concluded the header is not coming in correctly but I totally missed that part where he isn't setting it correctly in the test
– Ken4scholars
Mar 27 at 17:33
add a comment |
Your unit test is not setting the headers correctly. As described here, you should use CGI style headers when using the Django test client:
response = self.client.get('/api/v1/licenses/', HTTP_ACCEPT='text/uri-list')
The content negotiation uses the real HTTP Accept header. In your code, you check that "headers" is set, but that's not the real HTTP Accept header. It should be:
if request.META.get('HTTP_ACCEPT') == "text/uri-list":
...
Exactly! after checking how the renderers are matched, I also concluded the header is not coming in correctly but I totally missed that part where he isn't setting it correctly in the test
– Ken4scholars
Mar 27 at 17:33
add a comment |
Your unit test is not setting the headers correctly. As described here, you should use CGI style headers when using the Django test client:
response = self.client.get('/api/v1/licenses/', HTTP_ACCEPT='text/uri-list')
The content negotiation uses the real HTTP Accept header. In your code, you check that "headers" is set, but that's not the real HTTP Accept header. It should be:
if request.META.get('HTTP_ACCEPT') == "text/uri-list":
...
Your unit test is not setting the headers correctly. As described here, you should use CGI style headers when using the Django test client:
response = self.client.get('/api/v1/licenses/', HTTP_ACCEPT='text/uri-list')
The content negotiation uses the real HTTP Accept header. In your code, you check that "headers" is set, but that's not the real HTTP Accept header. It should be:
if request.META.get('HTTP_ACCEPT') == "text/uri-list":
...
edited Mar 27 at 17:34
answered Mar 27 at 17:29
dirkgrotendirkgroten
8,9931 gold badge15 silver badges25 bronze badges
8,9931 gold badge15 silver badges25 bronze badges
Exactly! after checking how the renderers are matched, I also concluded the header is not coming in correctly but I totally missed that part where he isn't setting it correctly in the test
– Ken4scholars
Mar 27 at 17:33
add a comment |
Exactly! after checking how the renderers are matched, I also concluded the header is not coming in correctly but I totally missed that part where he isn't setting it correctly in the test
– Ken4scholars
Mar 27 at 17:33
Exactly! after checking how the renderers are matched, I also concluded the header is not coming in correctly but I totally missed that part where he isn't setting it correctly in the test
– Ken4scholars
Mar 27 at 17:33
Exactly! after checking how the renderers are matched, I also concluded the header is not coming in correctly but I totally missed that part where he isn't setting it correctly in the test
– Ken4scholars
Mar 27 at 17:33
add a comment |
This is a block of code from the method finalize_response
:
if isinstance(response, Response):
if not getattr(request, 'accepted_renderer', None):
neg = self.perform_content_negotiation(request, force=True)
request.accepted_renderer, request.accepted_media_type = neg
response.accepted_renderer = request.accepted_renderer
response.accepted_media_type = request.accepted_media_type
response.renderer_context = self.get_renderer_context()
As you can see, before it performs content negotiaton, it checks to see if the view has already set the renderer needed and if not tries to perform the negotiation by itself.
So you can do this in your get method:
if request.META.get('headers') is not None :
if request.META.get('headers').get('Accept') == 'text/uri-list' :
request.accepted_renderer = URIListRenderer
result = [];
for m in models :
result.append(reverse('downloadLicense', args=[m.pk], request=request))
return Response(result, status=200)
Another thing you should probably do is to place your custom renderer class before JSONRenderer
in the renderer_classes list. In that way, it will first check the special case before the more general case during content negotiation. Is suspect that the request format also matches JSOnRender and it overshadows the custom renderer. Hope this helps
This shouldn't be needed. Setting theaccepted_renderer
will work, but why it's not matched using the default negotiation is strange. TheJSONRenderer
has only "application/json" as media type, so it shouldn't catch that one. Also you should set theaccepted_renderer
after the secondif
condition.
– dirkgroten
Mar 27 at 17:21
@dirkgroten yeah, I have fixed it.
– Ken4scholars
Mar 27 at 17:31
add a comment |
This is a block of code from the method finalize_response
:
if isinstance(response, Response):
if not getattr(request, 'accepted_renderer', None):
neg = self.perform_content_negotiation(request, force=True)
request.accepted_renderer, request.accepted_media_type = neg
response.accepted_renderer = request.accepted_renderer
response.accepted_media_type = request.accepted_media_type
response.renderer_context = self.get_renderer_context()
As you can see, before it performs content negotiaton, it checks to see if the view has already set the renderer needed and if not tries to perform the negotiation by itself.
So you can do this in your get method:
if request.META.get('headers') is not None :
if request.META.get('headers').get('Accept') == 'text/uri-list' :
request.accepted_renderer = URIListRenderer
result = [];
for m in models :
result.append(reverse('downloadLicense', args=[m.pk], request=request))
return Response(result, status=200)
Another thing you should probably do is to place your custom renderer class before JSONRenderer
in the renderer_classes list. In that way, it will first check the special case before the more general case during content negotiation. Is suspect that the request format also matches JSOnRender and it overshadows the custom renderer. Hope this helps
This shouldn't be needed. Setting theaccepted_renderer
will work, but why it's not matched using the default negotiation is strange. TheJSONRenderer
has only "application/json" as media type, so it shouldn't catch that one. Also you should set theaccepted_renderer
after the secondif
condition.
– dirkgroten
Mar 27 at 17:21
@dirkgroten yeah, I have fixed it.
– Ken4scholars
Mar 27 at 17:31
add a comment |
This is a block of code from the method finalize_response
:
if isinstance(response, Response):
if not getattr(request, 'accepted_renderer', None):
neg = self.perform_content_negotiation(request, force=True)
request.accepted_renderer, request.accepted_media_type = neg
response.accepted_renderer = request.accepted_renderer
response.accepted_media_type = request.accepted_media_type
response.renderer_context = self.get_renderer_context()
As you can see, before it performs content negotiaton, it checks to see if the view has already set the renderer needed and if not tries to perform the negotiation by itself.
So you can do this in your get method:
if request.META.get('headers') is not None :
if request.META.get('headers').get('Accept') == 'text/uri-list' :
request.accepted_renderer = URIListRenderer
result = [];
for m in models :
result.append(reverse('downloadLicense', args=[m.pk], request=request))
return Response(result, status=200)
Another thing you should probably do is to place your custom renderer class before JSONRenderer
in the renderer_classes list. In that way, it will first check the special case before the more general case during content negotiation. Is suspect that the request format also matches JSOnRender and it overshadows the custom renderer. Hope this helps
This is a block of code from the method finalize_response
:
if isinstance(response, Response):
if not getattr(request, 'accepted_renderer', None):
neg = self.perform_content_negotiation(request, force=True)
request.accepted_renderer, request.accepted_media_type = neg
response.accepted_renderer = request.accepted_renderer
response.accepted_media_type = request.accepted_media_type
response.renderer_context = self.get_renderer_context()
As you can see, before it performs content negotiaton, it checks to see if the view has already set the renderer needed and if not tries to perform the negotiation by itself.
So you can do this in your get method:
if request.META.get('headers') is not None :
if request.META.get('headers').get('Accept') == 'text/uri-list' :
request.accepted_renderer = URIListRenderer
result = [];
for m in models :
result.append(reverse('downloadLicense', args=[m.pk], request=request))
return Response(result, status=200)
Another thing you should probably do is to place your custom renderer class before JSONRenderer
in the renderer_classes list. In that way, it will first check the special case before the more general case during content negotiation. Is suspect that the request format also matches JSOnRender and it overshadows the custom renderer. Hope this helps
edited Mar 27 at 17:25
answered Mar 27 at 17:16
Ken4scholarsKen4scholars
1,9112 gold badges9 silver badges18 bronze badges
1,9112 gold badges9 silver badges18 bronze badges
This shouldn't be needed. Setting theaccepted_renderer
will work, but why it's not matched using the default negotiation is strange. TheJSONRenderer
has only "application/json" as media type, so it shouldn't catch that one. Also you should set theaccepted_renderer
after the secondif
condition.
– dirkgroten
Mar 27 at 17:21
@dirkgroten yeah, I have fixed it.
– Ken4scholars
Mar 27 at 17:31
add a comment |
This shouldn't be needed. Setting theaccepted_renderer
will work, but why it's not matched using the default negotiation is strange. TheJSONRenderer
has only "application/json" as media type, so it shouldn't catch that one. Also you should set theaccepted_renderer
after the secondif
condition.
– dirkgroten
Mar 27 at 17:21
@dirkgroten yeah, I have fixed it.
– Ken4scholars
Mar 27 at 17:31
This shouldn't be needed. Setting the
accepted_renderer
will work, but why it's not matched using the default negotiation is strange. The JSONRenderer
has only "application/json" as media type, so it shouldn't catch that one. Also you should set the accepted_renderer
after the second if
condition.– dirkgroten
Mar 27 at 17:21
This shouldn't be needed. Setting the
accepted_renderer
will work, but why it's not matched using the default negotiation is strange. The JSONRenderer
has only "application/json" as media type, so it shouldn't catch that one. Also you should set the accepted_renderer
after the second if
condition.– dirkgroten
Mar 27 at 17:21
@dirkgroten yeah, I have fixed it.
– Ken4scholars
Mar 27 at 17:31
@dirkgroten yeah, I have fixed it.
– Ken4scholars
Mar 27 at 17:31
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55378895%2fdjango-rest-framework-content-negotiation%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Have you debugged what
request.META.get('headers').get('Accept')
actually returns?==
is a rather strict comparison type as strings go.– Endre Both
Mar 27 at 14:11
It returns true, but it seems that the actual content negotiation takes place some completely different location and it always ends up with it picking the first renderer class.
– jonalv
Mar 27 at 14:54
Does the request have
?format=json
as query parameter by any chance?– dirkgroten
Mar 27 at 17:24