Django, TokenAuthentication, REST Framework API, Authentication credentials were not provided

I'm new to backend.

I'm trying to fetch my data in the backend via API token, and I followed this tutorial:

When I add these two lines in my View code, I can't fetch my data:

authentication_classes = [SessionAuthentication, BasicAuthentication]

permission_classes = [IsAuthenticated]

The error is

{ "detail": "Authentication credentials were not provided." }

and on my backend I got

"GET /hello/ HTTP/1.1" 403 58

But if I delete those two lines, I can fetch my data successfully.

This is my View class:

`class HelloView(APIView): authentication_classes = [SessionAuthentication, BasicAuthentication] permission_classes = [IsAuthenticated]

def get(self, request, format=None):
    content = {
        'user': str(request.user),
        'auth': str(request.auth),

    return Response(content)`

In the tutorial, it says when I have those two lines, I will be able to view my user name and token in the user router. But I got none for my "auth". However, if I delete those two lines, I can view my "user" and "auth" on my Windows side.


backend side, with those two lines

frontend side, with those two lines

frontend side, without those two lines

Could anybody explain this to me please? Any help would be nice! Thank you so much!

Back to Top