DRF 版本 認證

2022-04-25 04:20:27 字數 753 閱讀 4298

rest_framework =
urlpatterns = [

url(r"^versions", myview.as_view()),

url(r"^(?p[v1|v2]+)/test01", testview.as_view()),

]

class testview(apiview):

def get(self, request, *args, **kwargs):

print(request.versioning_scheme)

ret = request.version

if ret == "v1":

return response("版本v1的資訊")

elif ret == "v2":

return response("版本v2的資訊")

else:

return response("根本就匹配不到這個路由")

執行apiview的方法,apiview返回view中的view函式,然後呼叫的dispatch方法,然後執行initial方法

點選perform_authentication方法

這裡的request是封裝之後的request,所有要在request的例項中

DRF 全域性認證

auth.py from rest framework.authentication import baseauthentication 用於全域性認證 class globalauthentication baseauthentication def authenticate self,reque...

drf 認證元件

目錄區域性使用 全域性使用 原始碼分析 使用場景 有些介面在進行訪問時,需要確認使用者是否已經登入,比如 使用者需要購買物品時,在結賬的時候,就需要進行登入驗證的。一般使用者認證都是基於角色認證 使用者表關聯角色表,角色表關聯許可權表 五表機制 使用者表與角色表多對多 角色表與許可權表多對多 dja...

DRF登入認證元件

1.寫乙個登入認證類 類名隨意,類中的方法名固定 from rest framework import exceptions from rest framework.authentication import baseauthentication class auth baseauthenticat...