drf常用模块导入
drf中使用模块
import rest_framework
from rest_framework.views import APIView # 视图类
from rest_framework.request import Request # 请求
from rest_framework.response import Response # 响应
from rest_framework.exceptions import APIException # 异常
from rest_framework.pagination import PageNumberPagination # 分页
from rest_framework.settings import APISettings # 配置
from rest_framework.parsers import JSONParser # 解析JSON
from rest_framework.filters import OrderingFilter # 排序过滤器
from django.db import models # class User(models.Model)
from django.conf.urls import url,include # 媒体文件配置
from django.conf import settings # Django系统配置文件
from django.conf.urls import url # 路由分发子路由导入
from rest_framework.views import exception_handler # 自定义异常处理函数
from rest_framework import status # status.HTTP_500_INTERNAL_SERVER_ERROR
from rest_framework import serializers # 序列化 class UserSerializers(serializers.Serializer):
from rest_framework.parsers import JSONParser,FormParser,MultiPartParser # 解析模块
#=============================================================================================
from rest_framework.routers import SimpleRouter # 路由组件
视图类
APIView,GenericAPIView(generics中)
九个工具视图类
五个视图工具类
# mixin.py
CreateModelMixin,ListModelMixin,RetrieveModelMixin,UpdateModelMixin
视图集
viewsets:视图集 - 两个视图集基类,两个视图集子类,一个工具类