简体   繁体   中英

Django Rest framework Serializer necessary?

I had one business requirement to be implemented lately which required me to just fetch the data and render the response. So some API endpoint would return a response as: [{"id" :1,"name":"first"} ,{"id" :2,"name":"second":}] Can I just render this data by constructing a list of dictionaries which can be populated with various ORM queries instead of rendering the response through a serializer? Would it be an efficient solution in case I won't be using this serializer ever for POST request?

It is fine to have Django Rest Framework without serializer.

But best practice would be using Serializer. Using Serializer you can control the input and out of the data. You can validate Data. You can serializer and deserializer the data. Much more than that. Think Serializer as Form

From the Docs

Expanding the usefulness of the serializers is something that we would like to address. However, it's not a trivial problem, and it will take some serious design work.

— Russell Keith-Magee, Django users group

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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