diff --git a/rest_framework/decorators.py b/rest_framework/decorators.py index da97f0388..a69a613ba 100644 --- a/rest_framework/decorators.py +++ b/rest_framework/decorators.py @@ -94,13 +94,13 @@ def _check_decorator_order(func, decorator_name): # Check if func is actually a view function (result of APIView.as_view()) if hasattr(func, 'cls') and issubclass(func.cls, APIView): raise TypeError( - f"@{decorator_name} must be applied before @api_view. " - f"The correct order is:\n\n" - f" @api_view(['GET'])\n" + f"@{decorator_name} must come after (below) the @api_view decorator. " + "The correct order is:\n\n" + " @api_view(['GET'])\n" f" @{decorator_name}(...)\n" - f" def my_view(request):\n" - f" ...\n\n" - f"See https://www.django-rest-framework.org/api-guide/views/#api-policy-decorators" + " def my_view(request):\n" + " ...\n\n" + "See https://www.django-rest-framework.org/api-guide/views/#api-policy-decorators" ) diff --git a/tests/test_decorators.py b/tests/test_decorators.py index 81d34fac4..cc7cab4d7 100644 --- a/tests/test_decorators.py +++ b/tests/test_decorators.py @@ -214,7 +214,7 @@ class DecoratorTestCase(TestCase): def view(request): return Response({}) - assert '@permission_classes must be applied before @api_view' in str(cm.exception) + assert '@permission_classes must come after (below) the @api_view decorator' in str(cm.exception) def test_incorrect_decorator_order_renderer_classes(self): """ @@ -226,7 +226,7 @@ class DecoratorTestCase(TestCase): def view(request): return Response({}) - assert '@renderer_classes must be applied before @api_view' in str(cm.exception) + assert '@renderer_classes must come after (below) the @api_view decorator' in str(cm.exception) def test_incorrect_decorator_order_parser_classes(self): """ @@ -238,7 +238,7 @@ class DecoratorTestCase(TestCase): def view(request): return Response({}) - assert '@parser_classes must be applied before @api_view' in str(cm.exception) + assert '@parser_classes must come after (below) the @api_view decorator' in str(cm.exception) def test_incorrect_decorator_order_authentication_classes(self): """ @@ -250,7 +250,7 @@ class DecoratorTestCase(TestCase): def view(request): return Response({}) - assert '@authentication_classes must be applied before @api_view' in str(cm.exception) + assert '@authentication_classes must come after (below) the @api_view decorator' in str(cm.exception) def test_incorrect_decorator_order_throttle_classes(self): """ @@ -265,7 +265,7 @@ class DecoratorTestCase(TestCase): def view(request): return Response({}) - assert '@throttle_classes must be applied before @api_view' in str(cm.exception) + assert '@throttle_classes must come after (below) the @api_view decorator' in str(cm.exception) def test_incorrect_decorator_order_versioning_class(self): """ @@ -277,7 +277,7 @@ class DecoratorTestCase(TestCase): def view(request): return Response({}) - assert '@versioning_class must be applied before @api_view' in str(cm.exception) + assert '@versioning_class must come after (below) the @api_view decorator' in str(cm.exception) def test_incorrect_decorator_order_metadata_class(self): """ @@ -289,7 +289,7 @@ class DecoratorTestCase(TestCase): def view(request): return Response({}) - assert '@metadata_class must be applied before @api_view' in str(cm.exception) + assert '@metadata_class must come after (below) the @api_view decorator' in str(cm.exception) def test_incorrect_decorator_order_content_negotiation_class(self): """ @@ -305,7 +305,7 @@ class DecoratorTestCase(TestCase): def view(request): return Response({}) - assert '@content_negotiation_class must be applied before @api_view' in str(cm.exception) + assert '@content_negotiation_class must come after (below) the @api_view decorator' in str(cm.exception) def test_incorrect_decorator_order_schema(self): """ @@ -320,7 +320,7 @@ class DecoratorTestCase(TestCase): def view(request): return Response({}) - assert '@schema must be applied before @api_view' in str(cm.exception) + assert '@schema must come after (below) the @api_view decorator' in str(cm.exception) class ActionDecoratorTestCase(TestCase):