上一页 1 ··· 7 8 9 10 11 12 13 14 15 下一页
摘要: 原权限判断代码 def check_permissions(self, request): """ Check if the request should be permitted. Raises an appropriate exception if the request is not perm 阅读全文
posted @ 2022-10-01 18:56 Sherwin_szw 阅读(23) 评论(0) 推荐(0)
摘要: 组件类(返回True为通过) from rest_framework.permissions import BasePermission class DemoPermission(BasePermission): # 自定义失败的返回信息 message = {"status": False, 'c 阅读全文
posted @ 2022-10-01 16:47 Sherwin_szw 阅读(22) 评论(0) 推荐(0)
摘要: 建表 from django.db import models class UserInfo(models.Model): username = models.CharField(verbose_name='用户名', max_length=32) password = models.CharFie 阅读全文
posted @ 2022-10-01 10:42 Sherwin_szw 阅读(39) 评论(0) 推荐(0)
摘要: class BaseAuthentication: """ All authentication classes should extend BaseAuthentication. """ def authenticate(self, request): """ 如果子类继承BaseAuthenti 阅读全文
posted @ 2022-10-01 08:35 Sherwin_szw 阅读(30) 评论(0) 推荐(0)
摘要: 现象 # 兜底认证,直接失败 class NoAuthentication(BaseAuthentication): def authenticate(self, request): raise AuthenticationFailed('认证失败') class AuthenticationFai 阅读全文
posted @ 2022-10-01 08:29 Sherwin_szw 阅读(64) 评论(0) 推荐(0)
摘要: 实现效果:除登录接口无需认证,其他接口如果从params或者头部AUTHORIZATION没有获取到token,则直接认证失败。如果去掉NoAuthentication,则支持匿名访问 认证类 from rest_framework.authentication import BaseAuthent 阅读全文
posted @ 2022-09-30 20:13 Sherwin_szw 阅读(33) 评论(0) 推荐(0)
摘要: 认证类(不能写在视图里) rom rest_framework.authentication import BaseAuthentication from rest_framework.exceptions import AuthenticationFailed class MyAuthentica 阅读全文
posted @ 2022-09-30 14:34 Sherwin_szw 阅读(38) 评论(0) 推荐(0)
摘要: 阅读全文
posted @ 2022-09-30 11:31 Sherwin_szw 阅读(19) 评论(0) 推荐(0)
摘要: 路由 urlpatterns = [ path('order/', views.OrderView.as_view()), ] 视图关系 class View(object): @classonlymethod def as_view(cls, **initkwargs): def view(req 阅读全文
posted @ 2022-09-30 10:11 Sherwin_szw 阅读(23) 评论(0) 推荐(0)
摘要: 因为python中所有类默认继承object类。而object类提供了了很多原始的内建属性和方法,所以用户自定义的类在Python中也会继承这些内建属性。可以使用dir()函数可以查看,虽然python提供了很多内建属性但实际开发中常用的不多。而很多系统提供的内建属性实际开发中用户都需要重写后才会使 阅读全文
posted @ 2022-09-29 20:31 Sherwin_szw 阅读(96) 评论(0) 推荐(0)
上一页 1 ··· 7 8 9 10 11 12 13 14 15 下一页