使用了視圖集viewsets之后怎么返回自定義的response?
如果需要像APIView 那樣返回自定義的response
obj?=?self.get_object(pk=pk) if?not?obj:???? return?Response(data={"msg":?"沒有此課程信息"},?status=status.HTTP_404_NOT_FOUND)
是否就重寫perform_create、perform_update的方法就行了?
如果需要像APIView 那樣返回自定義的response
obj?=?self.get_object(pk=pk) if?not?obj:???? return?Response(data={"msg":?"沒有此課程信息"},?status=status.HTTP_404_NOT_FOUND)
是否就重寫perform_create、perform_update的方法就行了?
2021-05-29
舉報
2021-06-02
應(yīng)該是重寫 list ,create, update這些方法吧,這些方法里才返回Response對象