[英]How we can create generic API in django?
I'm totally new to Django.我对 Django 完全陌生。
I'm creating Generic API .我正在创建通用 API 。 List and Create are working well but ID is not visible in DELETE and UPDATE.
List 和 Create 运行良好,但 ID 在 DELETE 和 UPDATE 中不可见。
This is my views.py file这是我的views.py 文件
from rest_framework import generics
从 rest_framework 导入 generics
from rest_framework import mixins
从 rest_framework 导入混合
This is my urls.py code这是我的 urls.py 代码
from.views import GenericApiView
from.views 导入 GenericApiView
path('inspections-templates', GenericApiView.as_view()),
path('inspections-templates', GenericApiView.as_view()),
But as I check documents the ID is not available for UPDATE & DELETE .但是当我检查文档时, ID不适用于UPDATE & DELETE 。
Can you please someone guide me on how can I update and delete the record.请有人指导我如何更新和删除记录。
Thanks in advance提前致谢
Actually you have to pass that id in your URL.Try this in urls.py:实际上,您必须在 URL 中传递该 ID。在 urls.py 中尝试此操作:
path('inspections-templates/<int:id>/', GenericApiView.as_view()),
Because in UPDATE and DELETE user id is required to perform PUT and DELETE.因为在 UPDATE 和 DELETE 中需要用户 ID 才能执行 PUT 和 DELETE。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.