上一页 1 ··· 7 8 9 10 11 12 13 14 下一页
摘要: 现象 # 兜底认证,直接失败 class NoAuthentication(BaseAuthentication): def authenticate(self, request): raise AuthenticationFailed('认证失败') class AuthenticationFai 阅读全文
posted @ 2022-10-01 08:29 Sherwin_szw 阅读(47) 评论(0) 推荐(0) 编辑
摘要: 实现效果:除登录接口无需认证,其他接口如果从params或者头部AUTHORIZATION没有获取到token,则直接认证失败。如果去掉NoAuthentication,则支持匿名访问 认证类 from rest_framework.authentication import BaseAuthent 阅读全文
posted @ 2022-09-30 20:13 Sherwin_szw 阅读(20) 评论(0) 推荐(0) 编辑
摘要: 认证类(不能写在视图里) rom rest_framework.authentication import BaseAuthentication from rest_framework.exceptions import AuthenticationFailed class MyAuthentica 阅读全文
posted @ 2022-09-30 14:34 Sherwin_szw 阅读(25) 评论(0) 推荐(0) 编辑
摘要: 阅读全文
posted @ 2022-09-30 11:31 Sherwin_szw 阅读(11) 评论(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 阅读(13) 评论(0) 推荐(0) 编辑
摘要: 因为python中所有类默认继承object类。而object类提供了了很多原始的内建属性和方法,所以用户自定义的类在Python中也会继承这些内建属性。可以使用dir()函数可以查看,虽然python提供了很多内建属性但实际开发中常用的不多。而很多系统提供的内建属性实际开发中用户都需要重写后才会使 阅读全文
posted @ 2022-09-29 20:31 Sherwin_szw 阅读(75) 评论(0) 推荐(0) 编辑
摘要: 当我们访问一个不存在的属性的时候,会抛出异常,提示我们不存在这个属性。而这个异常就是__getattr__方法抛出的,其原因在于他是访问一个不存在的属性的最后落脚点,作为异常抛出的地方提示出错再适合不过了。 class A(object): def __init__(self, value): se 阅读全文
posted @ 2022-09-29 19:02 Sherwin_szw 阅读(21) 评论(0) 推荐(0) 编辑
摘要: 报错 Model class django.contrib.contenttypes.models.ContentType doesn't declare an explicit app_label and isn't in an application in INSTALLED_APPS. 原因 阅读全文
posted @ 2022-09-29 17:38 Sherwin_szw 阅读(74) 评论(0) 推荐(0) 编辑
摘要: django的request对象 request.method request.GET request.POST request.body request.FILES drf中的request参数,又一层封装 request._request.GET request._request.POST re 阅读全文
posted @ 2022-09-29 16:13 Sherwin_szw 阅读(40) 评论(0) 推荐(0) 编辑
摘要: 路由 urlpatterns = [ path('login/', views.LoginView.as_view()), path('login2/', views.login2), ] 视图 from django.views import View from django.http impor 阅读全文
posted @ 2022-09-29 11:39 Sherwin_szw 阅读(15) 评论(0) 推荐(0) 编辑
上一页 1 ··· 7 8 9 10 11 12 13 14 下一页