Raise NotAcceptable if suffix or query format is not acceptable

This commit is contained in:
Johnson Liu 2024-11-18 17:00:48 +08:00 committed by GitHub
parent b31413d46d
commit 00e5065fa4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -2,7 +2,6 @@
Content negotiation deals with selecting an appropriate renderer given the
incoming request. Typically this will be based on the request's Accept header.
"""
from django.http import Http404
from rest_framework import exceptions
from rest_framework.settings import api_settings
@ -85,7 +84,10 @@ class DefaultContentNegotiation(BaseContentNegotiation):
renderers = [renderer for renderer in renderers
if renderer.format == format]
if not renderers:
raise Http404
raise exceptions.NotAcceptable(
detail="Could not satisfy the request format suffix or query.",
available_renderers=renderers
)
return renderers
def get_accept_list(self, request):