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
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/34d7fa3d-7b65-4ced-a564-8a21c6ba04cf%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
No comments:
Post a Comment