如何修补使用Django的REST框架单场? [英] How to PATCH a single field using Django Rest Framework?
本文介绍了如何修补使用Django的REST框架单场?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有许多领域的典范为MyModel',我想用PATCH方法来更新字段状态。我使用基于类的意见。有什么办法来实现补丁?
I have a model 'MyModel' with many fields and I would like to update a field 'status' using PATCH method. I'm using class based views. Is there any way to implement PATCH?
推荐答案
串行器允许的部分更新部分= TRUE
初始化serialzer时。这是怎样的 PATCH
请求默认处理的在通用视图的。
Serializers allow partial updates by specifying partial=True
when initializing the serialzer. This is how PATCH
requests are handled by default in the generic views.
serializer = CommentSerializer(comment, data=request.data, partial=True)
这将允许您更新一个串行各个字段,或者所有字段,如果你想,没有任何一个标准的限制 PUT
的要求。
This will allow you to update individual fields in a serializer, or all of the fields if you want, without any of the restrictions of a standard PUT
request.
这篇关于如何修补使用Django的REST框架单场?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文