摘要: # 前端混合开发缓存的使用 -缓存的位置,通过配置文件来操作(以文件为例) -缓存的粒度: -全站缓存 中间件 MIDDLEWARE = [ 'django.middleware.cache.UpdateCacheMiddleware', 。。。。 'django.middleware.cache. 阅读全文
posted @ 2022-04-08 02:06 咖喱给给啊 阅读(25) 评论(0) 推荐(0)
摘要: # jwt的配置 import datetime JWT_AUTH={ 'JWT_RESPONSE_PAYLOAD_HANDLER':'app02.utils.my_jwt_response_payload_handler', 'JWT_EXPIRATION_DELTA': datetime.tim 阅读全文
posted @ 2022-04-08 02:05 咖喱给给啊 阅读(318) 评论(0) 推荐(0)
摘要: # RBAC :是基于角色的访问控制(Role-Based Access Control ),公司内部系统 # django的auth就是内置了一套基于RBAC的权限系统 # django中 # 后台的权限控制(公司内部系统,crm,erp,协同平台) user表 permssion表 group表 阅读全文
posted @ 2022-04-08 02:05 咖喱给给啊 阅读(59) 评论(0) 推荐(0)
摘要: # 3 自定义基于jwt的权限类 from rest_framework.authentication import BaseAuthentication # 基于它 from rest_framework_jwt.authentication import BaseJSONWebTokenAuth 阅读全文
posted @ 2022-04-08 02:04 咖喱给给啊 阅读(96) 评论(0) 推荐(0)
摘要: # 使用用户名,手机号,邮箱,都可以登录# # 前端需要传的数据格式 { "username":"lqz/1332323223/33@qq.com", "password":"lqz12345" } # 视图 from rest_framework.views import APIView from 阅读全文
posted @ 2022-04-08 02:04 咖喱给给啊 阅读(101) 评论(0) 推荐(0)
摘要: -第一种方案,自己写登录接口 -第二种写法,用内置,控制登录接口返回的数据格式 -jwt的配置信息中有这个属性 'JWT_RESPONSE_PAYLOAD_HANDLER': 'rest_framework_jwt.utils.jwt_response_payload_handler', -重写jw 阅读全文
posted @ 2022-04-08 02:02 咖喱给给啊 阅读(49) 评论(0) 推荐(0)
摘要: # 1 控制用户登录后才能访问,和不登录就能访问 from rest_framework.permissions import IsAuthenticated class OrderAPIView(APIView):# 登录才能 authentication_classes = [JSONWebTo 阅读全文
posted @ 2022-04-08 01:54 咖喱给给啊 阅读(189) 评论(0) 推荐(0)
摘要: from rest_framework_jwt.authentication import BaseAuthentication,BaseJSONWebTokenAuthentication from rest_framework.exceptions import AuthenticationFa 阅读全文
posted @ 2022-04-08 01:49 咖喱给给啊 阅读(20) 评论(0) 推荐(0)
摘要: jwt=Json Web token #原理 """ 1)jwt分三段式:头.体.签名 (head.payload.sgin) 2)头和体是可逆加密,让服务器可以反解出user对象;签名是不可逆加密,保证整个token的安全性的 3)头体签名三部分,都是采用json格式的字符串,进行加密,可逆加密一 阅读全文
posted @ 2022-04-08 01:47 咖喱给给啊 阅读(55) 评论(0) 推荐(0)
摘要: # 1 安装:pip install coreapi # 2 在路由中配置 from rest_framework.documentation import include_docs_urls urlpatterns = [ ... path('docs/', include_docs_urls(t 阅读全文
posted @ 2022-04-08 01:46 咖喱给给啊 阅读(36) 评论(0) 推荐(0)
摘要: # 写一个类,继承SimpleRateThrottle,只需要重写get_cache_key from rest_framework.throttling import ScopedRateThrottle,SimpleRateThrottle #继承SimpleRateThrottle class 阅读全文
posted @ 2022-04-08 01:45 咖喱给给啊 阅读(37) 评论(0) 推荐(0)
摘要: # 自定制频率类,需要写两个方法 -# 判断是否限次:没有限次可以请求True,限次了不可以请求False def allow_request(self, request, view): -# 限次后调用,显示还需等待多长时间才能再访问,返回等待的时间seconds def wait(self): 阅读全文
posted @ 2022-04-08 01:45 咖喱给给啊 阅读(31) 评论(0) 推荐(0)
摘要: # urls.py from django.urls import path,re_path from api import views urlpatterns = [ path('books/', views.BookAPIView.as_view()), re_path('books/(?P<p 阅读全文
posted @ 2022-04-08 01:43 咖喱给给啊 阅读(33) 评论(0) 推荐(0)
摘要: #views.py # 查所有,才需要分页 from rest_framework.generics import ListAPIView # 内置三种分页方式 from rest_framework.pagination import PageNumberPagination,LimitOffse 阅读全文
posted @ 2022-04-08 01:43 咖喱给给啊 阅读(29) 评论(0) 推荐(0)