且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Django Rest框架背后的HTTP基本身份验证

更新时间:2023-11-30 23:24:46

默认情况下,Django Rest Framework有两个身份验证类,请参阅这里

By default, Django Rest Framework has two authentication classes, see here.

REST_FRAMEWORK = {
'DEFAULT_AUTHENTICATION_CLASSES': (
    'rest_framework.authentication.SessionAuthentication',
    'rest_framework.authentication.BasicAuthentication'
)}

您可以禁用其余框架如果你不需要认证。

You can disable the rest framework authentication if you don't need it.

REST_FRAMEWORK = {
    'DEFAULT_AUTHENTICATION_CLASSES': ()
}

或者您只能删除 BasicAuthentication ,因为它将适用于您的案例。 (
'rest_framework.authentication.SessionAuthentication'


Or you can remove only BasicAuthentication as it will work in your case.

REST_FRAMEWORK = {
'DEFAULT_AUTHENTICATION_CLASSES': (
    'rest_framework.authentication.SessionAuthentication'
)}