Get user object from token string in DRF?

2019-04-02 10:53发布

问题:

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?

回答1:

from rest_framework.authtoken.models import Token
user = Token.objects.get(key='token string').user