1.基于GenericAPIView下的9个视图子类功能关系梳理
from rest_framework.generics import CreateAPIView, ListAPIView, UpdateAPIView, RetrieveAPIView, DestroyAPIView, ListCreateAPIView,
RetrieveUpdateDestroyAPIView, RetrieveDestroyAPIView, RetrieveUpdateAPIView
CreateAPIView:
新增功能
源码分析:
![](https://img2023.cnblogs.com/blog/2358807/202303/2358807-20230311092059595-466625668.png)
ListAPIView:
查询所有功能
源码分析:
![](https://img2023.cnblogs.com/blog/2358807/202303/2358807-20230311092131562-397963807.png)
UpdateAPIView:
修改功能
源码分析:
![](https://img2023.cnblogs.com/blog/2358807/202303/2358807-20230311092205852-1419786953.png)
RetrieveAPIView:
获取单条信息功能
源码分析:
![](https://img2023.cnblogs.com/blog/2358807/202303/2358807-20230311092223208-680753640.png)
DestroyAPIView:
删除功能
源码分析:
![](https://img2023.cnblogs.com/blog/2358807/202303/2358807-20230311092249348-1252140524.png)
ListCreateAPIView:
上面的继承两个ListAPIView, CreateAPIView等同于继承一个ListCreateAPIView
源码分析:
![](https://img2023.cnblogs.com/blog/2358807/202303/2358807-20230311092331826-142622111.png)
RetrieveUpdateDestroyAPIView:
上面的继承三个UpdateAPIView, RetrieveAPIView, DestroyAPIView等同于继承一个RetrieveUpdateDestroyAPIView
源码分析:
![](https://img2023.cnblogs.com/blog/2358807/202303/2358807-20230311092458962-1439331347.png)
RetrieveDestroyAPIView:
上面的继承两个DestroyAPIView,RetrieveAPIView等同于继承一个RetrieveDestroyAPIView
源码分析:
![](https://img2023.cnblogs.com/blog/2358807/202303/2358807-20230311092552441-243522088.png)
RetrieveUpdateAPIView:
上面的继承两个RetrieveAPIView,UpdateAPIView等同于继承一个RetrieveUpdateAPIView
源码分析:
![](https://img2023.cnblogs.com/blog/2358807/202303/2358807-20230311092703507-319404412.png)
1.GenericAPIView的5个扩展类写接口:
![](https://img2023.cnblogs.com/blog/2358807/202303/2358807-20230311091821829-1648457650.png)
2.ListAPIView和CreateAPIView使用:
![](https://img2023.cnblogs.com/blog/2358807/202303/2358807-20230311091851418-659031771.png)
2_1.ListAPIView_查询所有响应:
![](https://img2023.cnblogs.com/blog/2358807/202303/2358807-20230311091901783-1487204062.png)
2_2.CreateAPIView_新增一条:
![](https://img2023.cnblogs.com/blog/2358807/202303/2358807-20230311091909369-1840145606.png)
3.修改功能(继承UpdateAPIView), 获取单条信息(继承RetrieveAPIView), 删除功能(继承DestroyAPIView):
![](https://img2023.cnblogs.com/blog/2358807/202303/2358807-20230311091917446-703809390.png)
3_1.获取单条信息(继承RetrieveAPIView)响应:
![](https://img2023.cnblogs.com/blog/2358807/202303/2358807-20230311091925396-1392098435.png)
3_2.删除功能(继承DestroyAPIView)响应:
![](https://img2023.cnblogs.com/blog/2358807/202303/2358807-20230311091934002-734686678.png)
3_3.修改功能(继承UpdateAPIView)响应:
![](https://img2023.cnblogs.com/blog/2358807/202303/2358807-20230311091942587-1951757959.png)
4.继承RetrieveUpdateDestroyAPIView:
![](https://img2023.cnblogs.com/blog/2358807/202303/2358807-20230311091950735-1796191617.png)
5.9个视图子类总结:
![](https://img2023.cnblogs.com/blog/2358807/202303/2358807-20230311091957230-1505011909.png)