Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"http method not bound to view" when documenting class-based view in drf_yasg

Previously, I documented my function-based views like this:

@swagger_auto_schema(
    operation_id='ChangePassword',
    methods=['POST'],
    request_body=ChangePasswordSerializer,
    responses={
        '200': 'empty response body',
    })
def change_password(request):
    # code here

We then switched our views to class-based, so I simply copy-pasted the documentation decorator over to the post method:

class UserChangePasswordView(APIView):
    @swagger_auto_schema(
        operation_id='ChangePassword',
        methods=['POST'],
        request_body=ChangePasswordSerializer,
        responses={
            '200': 'empty response body',
        })
    def post(self, request):
        # code here 

However, on running this decorator, drf_yasg threw the exception

File "/usr/local/lib/python3.6/site-packages/drf_yasg/utils.py", line 126, in decorator
    assert all(mth in available_methods for mth in _methods), "http method not bound to view"

What is going on? What does this error message mean?

like image 954
2v0mjdrl Avatar asked Oct 20 '25 10:10

2v0mjdrl


1 Answers

Note that in source core of drf-yasg it's mentioned

method and methods are mutually exclusive and must only be present when decorating a view method that more than one HTTP request method.

So methods would be valid if your UserChangePasswordView.post() handled more than one method.

like image 106
vishes_shell Avatar answered Oct 22 '25 01:10

vishes_shell



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!