1.在Rest framework中进行了一系列的封装,这个认证功能也是被封装到在DRF工程中的一种,想要使用,首先需要在配置文件中进行相应的配置

REST_FRAMEWORK = {

  ’DEFAULT_AUTHENTICATION_CLASSES’:(

    'rest_framework.authentication.BasicAuthentication',   #基本认证

    'rest_framework.authenticationSessionAuthentication',   #Session认证

  )

}

2.在DRF工程中使用的视图,继承的是APIView,APIView同时继承自View,定义一个视图来使用认证功能,可以使用列表[ ],也可以使用元祖( )

class ExampleView(APIView):

  authentication_classes = (BasicAutnentication, SessionAuthentication)

3.认证需要配合着权限来一起使用

相关文章:

  • 2021-10-03
  • 2021-06-14
  • 2022-02-01
  • 2022-12-23
  • 2022-12-23
  • 2022-02-07
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-06-29
  • 2022-12-23
  • 2022-12-23
  • 2021-05-21
  • 2021-11-04
  • 2021-08-25
相关资源
相似解决方案