【发布时间】:2021-01-01 12:33:54
【问题描述】:
我有一个使用 JWT 作为身份验证类的 Django 项目。但是对于我的应用程序的某些页面没有身份验证。但是当我提出请求时,它仍然返回以下内容。
{
"detail": "You do not have permission to perform this action."
}
我的认证类在这里
REST_FRAMEWORK = {
'DEFAULT_AUTHENTICATION_CLASSES': [
'rest_framework_simplejwt.authentication.JWTAuthentication',
],
'DEFAULT_PERMISSION_CLASSES': [
'rest_framework.permissions.IsAuthenticated',
],
}
我的视图文件在这里
class Hello(APIView):
authentication_classes = []
def post(self, request):
return Response('Hello')
那么我该如何实现这个东西呢?
【问题讨论】:
-
您可以尝试设置
permission_classes = [AllowAny]而不是authentication_classes。通过从rest_framework.permissions导入AllowAny。 -
确实如此。刚才我想通了!总之谢谢!!!
标签: python django authentication