I have a simple DRF list view and wanted to write some permissions pertaining to POST
requests. That resulted in an error when GET
requests were issued. That led me to realize that my permission class is being called multiple times on requests that were not submitted. Here are my files.
permissons.py:
class IsDummy(permissions.BasePermission):
def has_permission(self, request, view):
print("\n{}\n".format(request.method))
if request.method in permissions.SAFE_METHODS:
return True
return False
views.py:
class UserListView(generics.ListCreateAPIView):
queryset = User.objects.all()
serializer_class = UserSerializer
permission_classes = [IsDummy]
The issue only happens when I submit a request from my browser on the browsable api. When I submit a GET request at the list url I get the following printed to the terminal from the print statement in the IsDummy
permission class:
GET
POST
POST
OPTIONS
When I submit a GET
or OPTIONS
request through postman I see the single, appropriate, request method that I actually used.
It seems that the first method listed is always the actual method that I used, I have no idea where the extra POST
s and the OPTION
are coming from. The even stranger part is that the page will load fine after all of this even though the POST
requests should clearly be resulting in IsDummy.has_permission
returning a False
.
The chrome dev tools show only a single GET
request being submitted and since it only seems to happen in the browsable api i'm sure it has something to do with that but I can't figure out what I have messed up to make this happen.