django.core序列化程序和Django Rest Framework序列化程序之间的区别 [英] Difference between django.core serializers and Django Rest Framework serializers

查看:134
本文介绍了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序列化程序之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆