简体   繁体   English

如何在不使用 Django Rest Framework 中的序列化程序的情况下开发 rest api?

[英]How to develop a rest api without using serializer in Django Rest Framework?

I want to create a Student Register and Login Api without using serializer in django Rest Framework.我想在不使用 django Rest Framework 中的序列化程序的情况下创建学生注册和登录 Api。 So I want to know how I make CRUD operation for those api using ApiView所以我想知道如何使用 ApiView 为那些 api 进行 CRUD 操作

Any one please solve this任何人请解决这个问题

I don't think you can, or even should but first, you need to understand what a serializer actually does:我认为你不能,甚至不应该,但首先,你需要了解序列化程序的实际作用:

Serializers allow complex data such as querysets and model instances to be converted to native Python datatypes that can then be easily rendered into JSON, XML, or other content types.序列化程序允许将查询集和模型实例等复杂数据转换为原生 Python 数据类型,然后可以轻松将其呈现为 JSON、XML 或其他内容类型。 Serializers also provide deserialization, allowing parsed data to be converted back into complex types, after first validating the incoming data序列化器还提供反序列化,允许在首先验证传入数据后将解析的数据转换回复杂类型

So don't be scared by serializers.所以不要被序列化器吓到。 Just take your time and learn how to use them using the many tutorials available online.只需花点时间,通过在线提供的许多教程学习如何使用它们。

If you are using DRF then you must need to create the serializers.如果您正在使用 DRF,那么您必须需要创建序列化程序。 But you can create the API without using DRF and serialzers.但是您可以在不使用 DRF 和序列化程序的情况下创建 API。

serializer is not just for converting json data,it also used to validate payload.you can use request.data.get("field_name_in_json_object") and fill the fields one by one.and for return you can use.values("field_name") in querysets. serializer 不仅仅用于转换 json 数据,它还用于验证 payload。您可以使用 request.data.get("field_name_in_json_object") 并逐一填充字段。返回可以使用 .values("field_name")在查询集中。 Django values_list vs values Django 值列表与值

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM