我有一个Settings子类,APIView它有 2 种方法。
class Settings(APIView):
def get(self, request, id=None):
pass
def post(self, request):
pass
在urls.py中,我有以下内容,
urlpatterns = [
path('account/settings/<str:id>', Settings.as_view(http_method_names=['get'])),
path('account/settings/', Settings.as_view(http_method_names=['post'])),
]
如您所见,我想在方法id中作为参数传递get,而不是在post方法中传递。
drf-yasg,理想情况下应该只在 Swagger 页面上显示 2 个方法,但它显示了 4 个方法。
1. GET for /settings/{id}
2. POST for /settings/{id}
3. GET for /settings/
4. POST for /settings/
我已经尝试添加@action(methods=['GET']), @api_view['GET']。但它不起作用。
我如何告诉drf-yasg从http_method_namesin读取允许的方法urls.py。
我可以将其保留id为可选,并且在 中只有一个条目urls.py,但在文档页面上大摇大摆地将其标记为必需。
也试过了,还是不行
@swagger_auto_schema(methods=['put'], responses=schema_doc)
@swagger_auto_schema(method='get', auto_schema=None)
@api_view(['PUT'])