django.core序列化程序和Django Rest Framework序列化程序之间的区别

编程入门 行业动态 更新时间:2024-10-27 04:38:30
本文介绍了django.core序列化程序和Django Rest Framework序列化程序之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我现在正在学习Django,我刚刚听说了Django Rest Framework(DRF)。我想知道django.core序列化程序和rest_framework序列化程序之间有什么区别。是的,我知道DRF适用于API。

I am now learning Django and I just heard about Django Rest Framework (DRF). I was wondering what is the difference between the django.core serializers and the rest_framework serializers. Yes, I know DRF is for APIs.

推荐答案

django.core 序列化程序旨在将整个模型实例序列化为XML,JSON或YAML,反之亦然。除了序列化之外,它们什么也没做。

django.core serializers are meant for the purpose of serializing entire model instances into XML, JSON, or YAML, and vice versa. They don't do anything besides just serializing.

DRF的序列化器专门用于在处理来自HTML表单或API请求的数据时将模型实例转换为JSON对象 / em>。因此,序列化并不总是一个平稳或直接的过程,因为您可能会传递非法或不完整的数据,或者表格的字段可能不以明显的方式与相应模型的字段相对应。因此,DRF允许您创建 serializers.Serializer 的自定义子类,以便清除和验证传递给服务器的数据。这还允许您自定义数据在模型实例中的存储方式。 请参阅此处的文档。

DRF's serializers are specifically for converting model instances into JSON objects when dealing with data from HTML forms or API requests. Thus, serialization is not always a smooth or straightforward process, as you may be passed illegitimate or incomplete data, or fields of the form may not correspond in an obvious way to the fields of the corresponding model(s). For this reason, DRF allows you to create custom subclasses of serializers.Serializer in order to clean and validate data that is passed to the server. This also allows you to customize the manner in which the data is stored in the model instance. See the documentation here.

更多推荐

django.core序列化程序和Django Rest Framework序列化程序之间的区别

本文发布于:2023-10-10 01:15:42,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1477286.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:序列化   程序   区别   core   django

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!