python - Checking if a user has been assigned a token in Django Restframework -


i setting token authentication site using django restframework , need able have user download token, catch able download token once (similar amazon aws model).

in other words; there native way check if user has been assigned token in restframework?

you can this:

from rest_framework.authtoken.models import token django.conf import settings token = token.objects.create(user=settings.auth_user_model) 

now can check if given user has token:

user_with_token = token.objects.get(user=user) 

if wanna see if user has token:

is_tokened = token.objects.filter(user=user).exist()  # returns boolean 

if entry exists means user has token assigned it. reference: here

follow documentation there make sure database migrated.


Comments

Popular posts from this blog

jOOQ update returning clause with Oracle -

java - Warning equals/hashCode on @Data annotation lombok with inheritance -

java - BasicPathUsageException: Cannot join to attribute of basic type -