我正在尝试将权限更改为特定的路由。我想打开一些路由,我想验证用户的其他路由。我的代码如下:
from rest_framework.decorators import api_view, permission_classes
from rest_framework.permissions import IsAuthenticated
from rest_framework.viewsets import GenericViewSet
class UserViewSet(GenericViewSet):
queryset = User.objects.all()
serializer_class = UserSerializer
permission_classes = [IsAuthenticated]
renderer_classes = [JSONRenderer]
@action(url_path="an/api/path", detail=False, methods=["post"], renderer_classes=[JSONRenderer])
@api_view(['GET'])
@permission_classes((IsAuthenticated, ))
def get_stuff(self, request):
#Will get stuff
但我一直有个错误:
File "/code/api/views/UserViewSet.py", line 16, in <module>
api_1 | class UserViewSet(GenericViewSet):
api_1 | File "/code/api/views/UserViewSet.py", line 33, in UserViewSet
api_1 | @permission_classes((IsAuthenticated, ))
api_1 | TypeError: 'list' object is not callable
在我的settings.py中,我有:
REST_FRAMEWORK = {
"DEFAULT_PERMISSION_CLASSES": [
"rest_framework.permissions.IsAuthenticated",
],
"DEFAULT_AUTHENTICATION_CLASSES": [
"rest_framework_jwt.authentication.JSONWebTokenAuthentication",
"rest_framework.authentication.SessionAuthentication",
"rest_framework.authentication.BasicAuthentication",
],
"DEFAULT_RENDERER_CLASSES": (
"rest_framework.renderers.JSONRenderer",
)
你知道为什么它总是抛出list“object is not callable function”吗?