标签:create com 后端 下载 request 十分 settings 文档 hub
快速开始:
互联网一切皆是资源,操作动词只是请求方式
例如
# book表增删改查 /books/ books /books/add/ addbook /books/(\d+)/change/ changebook /books/(\d+)/delete/ delbook
改成restful协议的样子,请求方式代表动作:
#book表增删改查 /books/ -----get Books ----- 返回当前所有数据 /books/ -----post Books ----- 返回提交数据 /books/(\d+) -----get Bookdetail ----- 返回当前查看的单条数据 /books/(\d+) -----put Bookdetail ----- 返回更新数据 /books/(\d+) -----delete Bookdetail ----- 返回空
class
class Books(View): def get(self,request): pass # 查看所有书籍 def post(self,request): pass # 添加书籍 class BooksDetail(View): def get(self,request,id): pass # 查看具体书籍 def put(self,request,id): pass # 更新某本书籍 def delete(self,request,id): pass # 删除某本书籍
pip install djangorestframework
djangorestframework是一个组件,所以需要在settings里安装一下
INSTALLED_APPS = ( ... ‘rest_framework‘, )
标签:create com 后端 下载 request 十分 settings 文档 hub
原文地址:https://www.cnblogs.com/lxfpy/p/10971961.html