上一页 1 ··· 12 13 14 15 16 17 18 19 20 ··· 24 下一页
摘要: base64介绍 base64是编码解码方式,而不是加密方式 使用方法 首先需要导入base64模块 import base64 base64编码: 只能转换bytes格式数据 base64.b64encode(转换数据.encode('utf-8')) base64解码: base64编码可能需要 阅读全文
posted @ 2024-01-03 20:04 wellplayed 阅读(292) 评论(0) 推荐(0)
摘要: 自定义全局异常处理 drf异常处理交给exception_handler处理了,但是没处理非drf的异常 'EXCEPTION_HANDLER': 'rest_framework.views.exception_handler' 我们可以重写一个exception_handler方法,处理drf异常 阅读全文
posted @ 2023-12-28 17:00 wellplayed 阅读(130) 评论(0) 推荐(0)
摘要: 分页组件的使用 有三种分页方式 需要新建一个py文件,以pagination.py为例 方式一:基本分页 第一步:导入分页类 from rest_framework.pagination import PageNumberPagination 第二步:书写分页类,继承 PageNumberPagin 阅读全文
posted @ 2023-12-28 16:37 wellplayed 阅读(81) 评论(0) 推荐(0)
摘要: 过滤组件的使用 有三种使用方式 方式一:使用drf内置过滤类 第一步:保证视图类继承 GenericAPIView 及其子类 # 以图书类为例 class BookView(ViewSetMixin, ListAPIView): queryset = Book.objects.all() seria 阅读全文
posted @ 2023-12-28 15:50 wellplayed 阅读(88) 评论(0) 推荐(0)
摘要: 排序组件快速使用 第一步:视图类需继承GenericAPIView或其子类 # 以图书类为例 class BookView(ViewSetMixin, ListAPIView): queryset = Book.objects.all() serializer_class = BookSeriali 阅读全文
posted @ 2023-12-28 15:27 wellplayed 阅读(67) 评论(0) 推荐(0)
摘要: 频率组件的书写 例:书写频率组件:一分钟只能访问5次(CommonThrottle) 第一步:新建一个py文件(以throttling为例) 第二步:书写频率类,并继承继承SimpleRateThrottle # 首先导入模块 from rest_framework.throttling impor 阅读全文
posted @ 2023-12-27 15:30 wellplayed 阅读(49) 评论(0) 推荐(0)
摘要: 权限组件的书写 例:书写权限组件(CommonPermission) 第一步:新建一个py文件(以permission为例) 第二步:书写认证类,并继承继承BasePermission # 首先导入模块 from rest_framework.permissions import BasePermi 阅读全文
posted @ 2023-12-27 15:19 wellplayed 阅读(44) 评论(0) 推荐(0)
摘要: 第一步:进入settings 第二步:自定义或改写默认代码 阅读全文
posted @ 2023-12-26 20:43 wellplayed 阅读(106) 评论(0) 推荐(0)
摘要: 认证组件的书写 例:书写登录认证(LoginAuth) 第一步:新建一个py文件(以auth为例) 第二步:书写认证类,并继承BaseAuthentication # 首先导入模块 from rest_framework.authentication import BaseAuthenticatio 阅读全文
posted @ 2023-12-26 16:25 wellplayed 阅读(42) 评论(0) 推荐(0)
摘要: 自动生成路由 第一步:导入 from rest_framework.routers import SimpleRouter, DefaultRouter 第二步:实例化 router = SimpleRouter() 第三步:注册路径(以BookView为例) router.register('bo 阅读全文
posted @ 2023-12-26 16:12 wellplayed 阅读(43) 评论(0) 推荐(0)
上一页 1 ··· 12 13 14 15 16 17 18 19 20 ··· 24 下一页