上一页 1 ··· 9 10 11 12 13 14 15 16 17 ··· 30 下一页
摘要: #1 安装:pip3 install #2 注册,在app中注册 #3 全局配,或者局部配 'DEFAULT_FILTER_BACKENDS': ('django_filters.rest_framework.DjangoFilterBackend',) #4 视图类 class BookView( 阅读全文
posted @ 2022-04-06 03:09 咖喱给给啊 阅读(13) 评论(0) 推荐(0)
摘要: # 需求:未登录用户1分钟访问5次,登录用户一分钟访问10次 全局:在setting中 'DEFAULT_THROTTLE_CLASSES': ( 'rest_framework.throttling.AnonRateThrottle', 'rest_framework.throttling.Use 阅读全文
posted @ 2022-04-06 03:08 咖喱给给啊 阅读(37) 评论(0) 推荐(0)
摘要: # 全局使用 限制未登录用户1分钟访问5次 REST_FRAMEWORK = { 'DEFAULT_THROTTLE_CLASSES': ( 'rest_framework.throttling.AnonRateThrottle', ), 'DEFAULT_THROTTLE_RATES': { 'a 阅读全文
posted @ 2022-04-06 03:08 咖喱给给啊 阅读(38) 评论(0) 推荐(0)
摘要: # 演示一下内置权限的使用:IsAdminUser,控制是否对网站后台有权限的人 # 1 创建超级管理员 # 2 写一个测试视图类 from rest_framework.permissions import IsAdminUser from rest_framework.authenticatio 阅读全文
posted @ 2022-04-06 03:03 咖喱给给啊 阅读(34) 评论(0) 推荐(0)
摘要: APIView >dispatch >initial >self.check_permissions(request)(APIView的对象方法) def check_permissions(self, request): # 遍历权限对象列表得到一个个权限对象(权限器),进行权限认证 for pe 阅读全文
posted @ 2022-04-06 02:58 咖喱给给啊 阅读(121) 评论(0) 推荐(0)
摘要: # 写一个认证类 app_auth.py from rest_framework.authentication import BaseAuthentication from rest_framework.exceptions import AuthenticationFailed from app0 阅读全文
posted @ 2022-04-06 02:56 咖喱给给啊 阅读(25) 评论(0) 推荐(0)
摘要: # 认证的实现 1 写一个类,继承BaseAuthentication,重写authenticate,认证的逻辑写在里面,认证通过,返回两个值,一个值最终给了Requet对象的user,认证失败,抛异常:APIException或者AuthenticationFailed 2 全局使用,局部使用 ` 阅读全文
posted @ 2022-04-06 02:54 咖喱给给啊 阅读(28) 评论(0) 推荐(0)
摘要: # action干什么用?为了给继承自ModelViewSet的视图类中定义的函数也添加路由 # 使用 class BookViewSet(ModelViewSet): queryset =Book.objects.all() serializer_class = BookSerializer # 阅读全文
posted @ 2022-04-06 02:52 咖喱给给啊 阅读(99) 评论(0) 推荐(0)
摘要: # 1 在urls.py中配置 path('books4/', views.Book4View.as_view()), re_path('books4/(?P<pk>\d+)', views.Book4DetailView.as_view()), # 2 一旦视图类,继承了ViewSetMixin, 阅读全文
posted @ 2022-04-06 02:51 咖喱给给啊 阅读(31) 评论(0) 推荐(0)
摘要: from rest_framework.viewsets import ViewSetMixin class Book6View(ViewSetMixin,APIView): #一定要放在APIVIew前 def get_all_book(self,request): print("xxxx") b 阅读全文
posted @ 2022-04-06 02:47 咖喱给给啊 阅读(14) 评论(0) 推荐(0)
上一页 1 ··· 9 10 11 12 13 14 15 16 17 ··· 30 下一页