python - 带有参数的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 (我相应创建的视图集)但不断收到“没有属性”错误。用参数发出这个获取请求的更简单方法是什么?
解决方案
推荐阅读
- vue.js - 不支持的 URL 类型“npm:”:npm:vue-loader@^16.0.0-beta.3
- angular - 角度路由中的 CanActivate 保护,无需重复“CanActivate”属性
- python - 为什么不把转换后的文件放到桌面?
- java - TextSecure 信号服务器 - 证书错误
- java - Java,声明抽象类类型的变量比声明子类类型的变量有什么优势
- python - 为什么处理异常后有一个“无”值?
- google-cloud-platform - 在使用 gcloud 控制台创建的容器优化操作系统 [COS] 上的 GCP 计算实例中安装磁盘
- google-admin-sdk - GSUITE users.delete 和传输数据
- python - 旋转背景 PYQT5
- sql - 具有多个条件的 SQL 选择