django-restframework
django-restframework
一、安装
>: pip3 install djangorestframework
二、使用
-
在settings.py中注册:
INSTALLED_APPS = [ .... 'api.apps.ApiConfig', # drf必须注册 'rest_framework', ]
三、模块
# drf的封装风格
from rest_framework.views import APIView # CBV
from rest_framework.response import Response # 响应
from rest_framework.request import Request # 请求
from rest_framework.filters import SearchFilter # 过滤器
from rest_framework.pagination import PageNumberPagination # 分页
from rest_framework.exceptions import APIException # 异常
from rest_framework.authentication import BaseAuthentication # 验证
from rest_framework.permissions import IsAuthenticated # 组件
from rest_framework.throttling import SimpleRateThrottle #
from rest_framework.settings import APISettings # rest_framework配置文件
from rest_framework import status # 状态码
from django.http.request import QueryDict # 类型
- 基于CBV完成满足RSSTful规范接口
在当下的阶段,必将由程序员来主导,甚至比以往更甚。