Getting Token from Django Model to views

I created a user model in Django i want to know what JWT token is generated for my particular user in the views.py section could you please help

class User(AbstractBaseUser, PermissionsMixin):
    username = models.CharField(max_length=255, unique=True, db_index=True)
    email = models.EmailField(max_length=255, unique=True, db_index=True)
    is_verified = models.BooleanField(default=False)
    is_active = models.BooleanField(default=True)
    is_staff = models.BooleanField(default=False)
    created_at = models.DateTimeField(auto_now_add=True)
    updated_at = models.DateTimeField(auto_now=True)
    status=models.IntegerField(default=1)
    phone=models.IntegerField(blank=True,null=True)
    otp=models.IntegerField(blank=True,null=True)
    auth_provider = models.CharField(
        max_length=255, blank=False,
        null=False, default=AUTH_PROVIDERS.get('email'))
    #locations=models.ManyToManyField(Location)
    USERNAME_FIELD = 'email'
    REQUIRED_FIELDS = ['username']

    objects = UserManager()

    def __str__(self):
        return self.email

    def tokensd(self):
        refresh = RefreshToken.for_user(self)
        return {
            'refresh': str(refresh),
            'access': str(refresh.access_token)
        }

If django version is or greater than 2.2 then you can use request.headers it will give dictionary and check the token key and get the key request.headers['HTTP_AUTHORIZATION'] else you can use request.META['HTTP_AUTHORIZATION']

Back to Top