首页 > 解决方案 > 带有参数的django get方法不起作用

问题描述

正如文档在https://docs.djangoproject.com/en/3.2/topics/class-based-views/中所说,我正在尝试在 django 中使用 ID 参数发出获取请求,但我似乎无法做到工作。

请求按预期到达后端。 "GET /api/acordo-parcela/1/ HTTP/1.1" 200 348其中 1 是我的 ID。但即使在创建新的 urlpattern 之后它也不会到达视图类

url 模式:path('/acordo-parcela/<int:clienteId>/', GetParcelas.as_view()),

GetParcelas 类:

class GetParcelas(APIView):
    print("test")
    def get(self, request, clienteId):
        print("inside")
        return Response(clienteId)

我已阅读https://docs.djangoproject.com/en/3.2/topics/http/urls/上的文档并尝试使用 views.AcordoParcelaViewSet (我相应创建的视图集)但不断收到“没有属性”错误。用参数发出这个获取请求的更简单方法是什么?

标签: pythondjangodjango-viewsparameter-passingdjango-rest-viewsets

解决方案


推荐阅读