I have a problem with (I think) permissions. When I try to send post request via postman, I get following error:
AssertionError: Cannot apply DjangoModelPermissionsOrAnonReadOnly on a view that does not set
.queryset
or have a.get_queryset()
method. [29/Nov/2021 20:21:21] "POST /api/blog/category HTTP/1.1" 500 101581
Here are my views.py and category class. Also, I noticed that for some reason in def post(self, request, format=None) request is not being called ("request" is not accessed Pylance). I think the problem is somewhere here, but can't figure it out. Thank you in advance.
class BlogPostCategoryView(APIView):
serializer_class = BlogPostSerializer
permissions_classes = (permissions.AllowAny, )
def post(self, request, format=None):
data = self.request.data
category = data['category']
queryset = BlogPost.objects.order_by('-date_created').filter(category__iexact=category)
serializer = BlogPostSerializer(queryset, many=True)
return Response(serializer.data)
CodePudding user response:
In settings.py you can add:
REST_FRAMEWORK = {
'DEFAULT_AUTHENTICATION_CLASSES': [
'rest_framework.authentication.BasicAuthentication',
]
}
Then in postman go to the Authorization tab and for type select Basic Auth. You can then enter your username and password. You should be able to make Post requests after this.