为什么需要使用Django REST API? [英] Why do you need to use Django REST API?
问题描述
为什么需要使用Django REST框架来制作API?您不能只使用普通的Django创建像/api/createuser
这样的路由,并像往常一样从那里处理所有后端逻辑吗?
Why do you need to use Django REST framework to make an API? Can't you just create routes like /api/createuser
with normal Django and handle all of the backend logic from there as you would normally?
推荐答案
您不需要使用Django REST框架制作API
但是,如果您打算在Django中制作一个不错的REST API,DRF是Django之上的框架,可帮助您构建具有以下功能的API:
But if you are going to make a decent REST API in Django, DRF is a framework on top of Django that helps you building an API with following features:
- 可浏览Web的API,自动生成文档
- 根据模型自动构建通用视图
- 路由器
- 正文解析器(自动内容协商)
- 验证人
- 身份验证
- 权限
- 节流
- 通过获取参数自动过滤数据
- 4种不同的分页模式(数字/偏移量/时间)
- API版本控制
- 多种响应格式(.xml/.json/etc)
- 异常格式为当前响应格式
您可以自由地重新发明轮子和/或创建有问题的/不安全的REST API,也可以选择使用经过深思熟虑和经过测试的框架来帮助您构建良好的REST API.
You are free to reinvent the wheel and/or create a buggy/insecure REST API or you can choose to use a well thought and tested framework to help you build a good REST API.
这篇关于为什么需要使用Django REST API?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!