![](https://img-blog.csdnimg.cn/20201014180756754.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
drf
文章平均质量分 55
a35155
这个作者很懒,什么都没留下…
展开
-
django+drf 前后端分离总结(2)
DRF常见问题DRF 常用组件权限组件局部视图权限from rest_framework.permissions import BasePermissionclass SVIPPermission(BasePermission): message="SVIP才能访问!" def has_permission(self, request, view): if request.user.user_type==3: return True原创 2022-02-22 19:52:11 · 315 阅读 · 0 评论 -
drf 分页
内置分页器分页基类class BasePagination: display_page_controls = False def paginate_queryset(self, queryset, request, view=None): # pragma: no cover raise NotImplementedError('paginate_queryset() must be implemented.') def get_paginated_resp原创 2022-02-17 18:45:18 · 602 阅读 · 0 评论 -
drf 序列化器
模型类对象-> > python字典: 序列化python字典-> > 模型类对象: 反序列化序列化对象创建对象from datetime import datetimeclass Comment(object): def __init__(self, email, content, created=None): self.email = email self.content = content self.cr原创 2022-02-16 19:14:08 · 550 阅读 · 1 评论 -
drf 解析器
过程执行get_parsersdef get_parsers(self): """ Instantiates and returns the list of parsers that this view can use. """ # 列表生成式获取解析器实例 return [parser() for parser in self.parser_classes]列表生成式获取解析器实例,然后就是看是否我们在类中是否定义了解析类设置了就执行设置的解析类原创 2022-02-15 19:50:16 · 557 阅读 · 1 评论 -
drf 版本
流程self.initial()# 这里的request 是封装后的request,传入def initial(self, request, *args, **kwargs)这个方法def initial(self, request, *args, **kwargs): """ Runs anything that needs to occur prior to calling the method handler. """ self.format_kwarg = se原创 2022-02-14 19:04:15 · 262 阅读 · 1 评论 -
drf频率
过程解析check_throttles()def check_throttles(self, request): """ Check if request should be throttled. Raises an appropriate exception if the request is throttled. 检查是否应该限制请求,如果请求被限制,则引发适当的异常 """ throttle_durations = [] # 循环频率控制类原创 2022-02-11 19:15:36 · 261 阅读 · 1 评论 -
drf权限(2)
内置权限类分析BasePermission默认实现has_permission, has_object_permission方法class BasePermission(metaclass=BasePermissionMetaclass): """ A base class from which all permission classes should inherit. """ def has_permission(self, request, view):原创 2022-02-10 19:34:51 · 421 阅读 · 1 评论 -
drf权限(1)
流程执行initial()方法def initial(self, request, *args, **kwargs): """ Runs anything that needs to occur prior to calling the method handler. """ self.format_kwarg = self.get_format_suffix(**kwargs) # Perform content negotiation and store t原创 2022-02-09 18:58:39 · 344 阅读 · 0 评论 -
DRF 认证(2)
self.initial()这里的request 是封装后的request,传入def initial(self, request, *args, **kwargs)这个方法def initial(self, request, *args, **kwargs): """ Runs anything that needs to occur prior to calling the method handler. """ self.format_kwarg = self.ge原创 2022-01-27 17:56:21 · 3558 阅读 · 0 评论