赞
踩
rest_framework中有五大基础接口:get_list(获得多条数据),get_one(获得一条数据),post_one(添加一条数据),put_one(修改一条数据),delete_one(删除一条数据)
from rest_framework.views import APIView from rest_framework.response import Response from app import models, objson class Books(APIView): # 请求地址:/books/ def get(self, request, *args, **kwargs): book_list = models.Book.objects.all() book_data = objson.BookJson(book_list, many=True).data return Response({ 'status': 0, 'msg': 'ok', 'results': book_data }) # 请求地址:/books/ 参数:{"name": "红楼梦","price": "66.66","author": [1]} def post(self, request, *args, **kwargs): book_json = objson.BookJson(data=request.data) if book_json.is_valid(): book_json.save() return Response({ 'status': 0,
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。