Reputation: 2346
In my Django project I have a public API endpoint built with Django Rest Framework's APIView
. It does not need to know anything about the user. Still, Django automatically fetches the session and the user from the database. Is there a way to not do this since it causes two unnecessary DB hits?
Here is the code:
class TermListView(APIView):
permission_classes = ()
def get(self, request, format=None):
qs = Term.objects.all().only('original_word')
return Response([term.original_word for term in qs])
Upvotes: 2
Views: 42
Reputation: 2346
You need to add authentication_classes = ()
to the View class. This tells Django not to worry about the user. Or you can also configure this option globally for all your endpoints.
Upvotes: 1