为什么需要使用 Django REST API? [英] Why do you need to use Django REST API?

查看:28
本文介绍了为什么需要使用 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屋!

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