Get user object from token string in DRF?

Berry picture Berry · May 27, 2017 · Viewed 9.1k times · Source

I have a token string from Django REST Framework's TokenAuthentication.

I need to get the corresponding user object. How would I go about doing this?

Answer

aliva picture aliva · May 27, 2017
from rest_framework.authtoken.models import Token
user = Token.objects.get(key='token string').user