如何给drf的Response添加内容

分析:

  我们返回给前端的是Response对象, 要给Response加减内容,首先得找见它.

  所以步骤是

  1.1 找见Response 

        1.2 给Response添加/减少/改变东西, 返回新的Response

 

1.1 返回Response 位置 -> 五个视图扩展类里

   from rest_framework.mixins import CreateModelMixin, ListModelMixin, UpdateModelMixin, DestroyModelMixin, RetrieveModelMixin

 

1.2 在视图中继承五个视图扩展类或其子类如ModelviewSet

 

posted @ 2023-06-13 15:54  tslam  阅读(30)  评论(0编辑  收藏  举报