本文介绍了在单一视图中排除基本身份验证 - Django Rest框架的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在我的setting.py中设置了基本身份验证,如下所示。现在我需要一个不使用基本身份验证的视图。如何做到这一点。
I set basic authentication in my setting.py as follows. Now I need a view that doesn't use basic authentication. How can I do it.
REST_FRAMEWORK = {
'DEFAULT_AUTHENTICATION_CLASSES': (
'rest_framework.authentication.BasicAuthentication',),
}
推荐答案
您只需在视图中设置 authentication_classes
。看看为例。
You simply need to set the authentication_classes
on your view. Have a look at http://www.django-rest-framework.org/api-guide/authentication/#setting-the-authentication-scheme for an example.
编辑:
要删除身份验证,请将 authentication_classes
设置为空列表。不要忘记删除权限,因为他们通常依赖身份验证。
To remove authentication, set the authentication_classes
to an empty list. Don't forget to remove permissions as well since they usually rely on authentication.
这篇关于在单一视图中排除基本身份验证 - Django Rest框架的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!