当前位置:网站首页>Restframework read and non read sequence processing
Restframework read and non read sequence processing
2022-06-22 05:02:00 【laoli815】
Use restframework When , If the front-end of the web page is only simple get If you ask , Some fields of our custom methods will be involved , If you submit on this page, an error will be reported , So the sequence can distinguish these requirements , Design two serializations ,get Request serialization and put,patch,delete,post serialize
serializers.py
class BookReadSerializer(serializers.ModelSerializer):
category = CategorySerializer()
author = AuthorSerializer()
class Meta:
model = Book
fields = '__all__'
class BookWriteSerializer(serializers.ModelSerializer):
class Meta:
model = Book
fields = "__all__"
views.py
class BookViewSet(viewsets.ModelViewSet):
queryset = Book.objects.all()
def get_serializer_class(self):
if self.request.method in ['GET', 'HEAD']:
return BookReadSerializer
else:
return BookWriteSerializer
Directly separate , Different request methods call different sequences
边栏推荐
- 【故障诊断】cv2.imwrite无法写入图片,但程序就是不报错
- Lottie components make animation easier
- restframework读取和非读取序列处理
- 厉害了!淮北两企业获准使用地理标志产品专用标志
- Zset type of redis
- exness:欧洲央行行长拉加德重申计划在7月会议上加息
- mysql笔记
- Daemon flow
- Progress warning and problem management of progress control in Zhiyuan project management SPM system
- 加快推进工业互联网,图扑“智”绘发展新蓝图
猜你喜欢

Final examination questions of Database Principles

Slurm tutorial

Web page design and production final assignment report - College Students' online flower shop

Leetcode -- the kth largest node of the binary search tree (traversal by means of middle order)

Target detection algorithm based on deep learning interview essential (rcnn~yolov5)

JUC - thread interrupt and thread waiting and wakeup (locksupport)

Getting the return value of DPI function is always 96 | getting the return value of DPI function is incorrect | why the return value of getdpiformonitor/getdevicecaps is incorrect

6. Local - custom filter factory

网页设计与制作期末大作业报告——大学生线上花店

下拉刷新,上推加载(简单好用,终于会了)
随机推荐
numpy庫常用知識整理
图扑软件2D与2.5D案例合集|智慧园区、数据中心、SMT 生产线...
Final examination questions of Database Principles
[details] domestic website filing process and steps
Getting the return value of DPI function is always 96 | getting the return value of DPI function is incorrect | why the return value of getdpiformonitor/getdevicecaps is incorrect
7. Gateway global filter
Kotlin project reports an error and lacks coroutinecontext dependency
C # WinForm listview control has no scroll bar and has written an extension control by itself
LeetCode——二叉搜索树的第k大节点(借助中序遍历)
Lottie components make animation easier
Exness: ECB president Christine Lagarde reiterated her plan to raise interest rates at the July meeting
Browser -- a collection of common search operators -- use / instance
ORA-15063: ASM discovered an insufficient number of disks for diskgroup 恢複---惜分飛
网页设计与制作期末大作业报告——小众音乐网站
Disturbed when programmers are programming? Daily anecdotes
ORA-15063: ASM discovered an insufficient number of disks for diskgroup 恢复---惜分飞
The Impossible Triangle of NLP?
Database - basic knowledge
The application of RPC technology and its framework sekiro in crawler reverse, encrypting data is a shuttle!
【sdx62】QCMAP_CLI手动拨号操作说明