django rest framework - access token user

37 views
Skip to first unread message

Shekar Tippur

unread,
Oct 1, 2015, 2:01:18 PM10/1/15
to Django users
Hello,

I am trying to get the user name from a token request.

Here is what I have so far:

from rest_framework.authtoken.models import Token

class getTokenl(generics.RetrieveDestroyAPIView):
permission_classes = [permissions.IsAuthenticated, TokenHasReadWriteScope]
queryset = Parcel.objects.all()
serializer_class = ParcelGetSerializer
model=Parcel
def dispatch(self, request, *args, **kwargs):
tok=request.META['HTTP_AUTHORIZATION'].replace('Bearer ','')
        print (Token.objects.get(authtoken=tok))

With this, I get a error:

type object 'Token' has no attribute 'objects'

How do I get the token object? More so, is this the best way to access token object. at the end, I would like to get to the user who owns that token. Appreciate any help.

- Shekar
Reply all
Reply to author
Forward
0 new messages