以前,我记录了我的基于函数的视图,如下所示:
@swagger_auto_schema(
operation_id='ChangePassword',
methods=['POST'],
request_body=ChangePasswordSerializer,
responses={
'200': 'empty response body',
})
def change_password(request):
# code here
然后我们将视图切换到基于类的视图,所以我简单地将文档装饰器复制粘贴到post
方法中:
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
然而,在运行这个装饰器时,drf_yasg
抛出了异常
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"
到底是怎么回事?这个错误信息是什么意思?