AssertionError: you cannot apply DjangoModelPermissions in a view that does not have the `.model` or`.queryset` property

Earlier I considered this project in my project:

from rest_framework import status from rest_framework.views import APIView from rest_framework.response import Response from rest_framework.parsers import JSONParser from rest_framework.permissions import IsAuthenticated from rest_api.my_app.serializer import MySerializer from my_project.models import Bag class MyView(APIView): parser_classes = (JSONParser,) queryset = Bag.objects.all() permission_classes = (IsAuthenticated,) @staticmethod def post(self, request, format=None): serializer = MySerializer(data=request.DATA) if serializer.is_valid(): serializer.save(), return Response(serializer.data, status=status.HTTP_201_CREATED) return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST) 

However, later I realized that I didn’t need the request, so I deleted this line and the permission and the request to stay with:

 from rest_framework import status from rest_framework.views import APIView from rest_framework.response import Response from rest_framework.parsers import JSONParser from rest_api.my_app.serializer import MySerializer class MyView(APIView): parser_classes = (JSONParser,) @staticmethod def post(self, request, format=None): serializer = MySerializer(data=request.DATA) if serializer.is_valid(): serializer.save(), return Response(serializer.data, status=status.HTTP_201_CREATED) return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST) 

If I try to run the code, I get this error message:

 AssertionError: Cannot apply DjangoModelPermissions on a view that does not have `.model` or `.queryset` property.' 
+6
source share
1 answer

This is because you deleted license_classes. You can use permission_classes = (IsAuthenticatedOrReadOnly,)

+9
source

All Articles