DRF-vew/viewset
DRF-vew/viewset
Serialization
是对数据进行序列化和反序列化,但数据获取以及获取什么样的数据,就要靠视图层来完成了。DRF不仅对Django的基于函数的视图以及基于类的视图做了扩展,还增加了ViewSet。
DRF-Serialization
DRF-Serialization
按照上一章内容的架构图自下向上,本章介绍Serialization。关于Model层,在原先的Django基础上未做修改,故不做介绍。若想了解可参看官方文档或可参看我之前写的Django模型简介
Introduction
首先思考一下,若不使用DRF框架,我们生成一个API接口应该会怎么做呢?比如传入一个用户名,需要返回用户的相关信息。大概会这么实现:
DRF-About
DRF-About
introduction
django-rest-framework,是一套基于Django 的 REST 框架,是一个强大灵活的构建 Web API 的工具包。
The Web browsable API is a huge usability win for your developers.
Authentication policies including packages for OAuth1a and OAuth2.
Serialization that supports both ORM and non-ORM data sources.
Customizable all the way down - just use regular function-based views if you don’t need the more powerful features.
Extensive documentation, and great community support.
Used and trusted by internationally recognised companies including Mozilla, Red Hat, Heroku, and Eventbrite.