REST framework 基本使用

安装

pip install djangorestframework

djangorestframework 介绍

  • djangorestframework 主要使用 APIView,其实APIView实质是对 View 进行继承加工了更多功能

  • 请求来了 APIView首先执行 self.dispatch 方法,此方法对 request 进行了再次封装

基于django实现REST framework

urls.py

urlpatterns = [
    url(r'^users', Users.as_view()),
]

views.py

from django.views import View
from django.http import JsonResponse
 
class Users(View):
    def get(self, request, *args, **kwargs):
        result = {
            'status': True,
            'data': 'response data'
        }
        return JsonResponse(result, status=200)
 
    def post(self, request, *args, **kwargs):
        result = {
            'status': True,
            'data': 'response data'
        }
        return JsonResponse(result, status=200) 

参考链接于此

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值