項(xiàng)目是python代碼開發(fā), urls.py 路由中訪問路徑代碼如下:
urlpatterns = [ path('reportmanagement/<int:pk>/', views.ReportManagementDetail.as_view(), name='report-management-detail'), ]
對應(yīng)view視圖中代碼如下:
class ReportManagementDetail(GenericAPIView):
"""報(bào)表管理:刪除、修改"""
serializer_class = ReportManagementSerializer
queryset = ReportManagement.objects.all()
def delete(self, request, *args, **kwargs):
"""刪除報(bào)表列表
:param: id:int
:return:
"""
instance = self.get_object()
name = instance.name
instance.delete()
data = response_data(code=200, result=[], msg="刪除成功")
return Response(data, status=status.HTTP_200_OK)
上面代碼可以看到我要執(zhí)行的是一個(gè)刪除操作, 使用的是python drf模型, 自己使用postman調(diào)用,界面參數(shù)如下:
會(huì)發(fā)現(xiàn)下面就報(bào)出了Method not allowed的錯(cuò)誤提示信息, 經(jīng)過查閱資料有說改什么windows電腦設(shè)置的, 還有在方面上面加代碼說告訴postman這是一個(gè)detete請求, 還有其他的解決辦法, 自己就不在此一一指出, 但當(dāng)發(fā)現(xiàn)其他博客說的辦法都不適合自己項(xiàng)目的情形, 然后找了之前的項(xiàng)目代碼和使用postman調(diào)用執(zhí)行delete請求的歷史記錄, 以及填寫參數(shù)的位置, 發(fā)現(xiàn)了問題的癥結(jié)所在, 其實(shí)處理辦法很簡單, 只需要去掉url傳遞參數(shù)的問好?和參數(shù)名=即可正常調(diào)用接口, 正常調(diào)用postman請求界面如下:
?
?大家應(yīng)該能看到, url只需填上需要?jiǎng)h除數(shù)據(jù)的id具體對應(yīng)的數(shù)值即可, 不用填寫參數(shù)名=數(shù)值
原因其實(shí)也很簡單, 在最上面urls.py路由代碼文件中,
path('reportmanagement/<int:pk>/', views.ReportManagementDetail.as_view(), name='report-management-detail'), python函數(shù): reportmanagement/<int:pk>/
/<int:pk/代碼已經(jīng)明確告訴了我們答案, 傳遞的參數(shù)類型是int,然后直接填寫具體數(shù)值即可文章來源:http://www.zghlxwxcb.cn/news/detail-766420.html
以上只貼出了最最關(guān)鍵部分的代碼, 不包括包,路徑, 各種導(dǎo)入的第三庫等等, 只是作為一個(gè)記錄, 介紹下解決這個(gè)問題的思路和辦法, 不代表大家遇到Method Not Allowed都是這種解決方案, 各自情況大家自行具體分析對待, 好了今天文章的就先到這, 感謝您的查閱, 我們下期見???文章來源地址http://www.zghlxwxcb.cn/news/detail-766420.html
到了這里,關(guān)于postman調(diào)用接口報(bào){“detail“:“Method \“DELETE\“ not allowed.“}錯(cuò)誤, 解決記錄的文章就介紹完了。如果您還想了解更多內(nèi)容,請?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!