nid*_*hin 2 django-rest-framework
我在我的setting.py中设置了基本身份验证,如下所示.现在我需要一个不使用基本身份验证的视图.我该怎么做.
REST_FRAMEWORK = {
'DEFAULT_AUTHENTICATION_CLASSES': (
'rest_framework.authentication.BasicAuthentication',),
}
Run Code Online (Sandbox Code Playgroud)
要从身份验证中排除视图,请将authentication_classes和设置permission_classes为[]。
class SignupView(APIView):
authentication_classes = []
permission_classes = []
def post(self, request):
# view code
Run Code Online (Sandbox Code Playgroud)
您只需authentication_classes在视图上设置即可.有关示例,请查看http://www.django-rest-framework.org/api-guide/authentication/#setting-the-authentication-scheme.
编辑:要删除身份验证,请将其设置authentication_classes为空列表.不要忘记删除权限,因为它们通常依赖于身份验证.
| 归档时间: |
|
| 查看次数: |
2373 次 |
| 最近记录: |