django create token for user
To create a token for a user in Django, you can follow these steps:
Import the necessary modules and functions:
python from rest_framework_simplejwt.tokens import RefreshToken
Generate a token for the user:
python token = RefreshToken.for_user(user)
Access the access and refresh tokens:
python access_token = str(token.access_token) refresh_token = str(token)
Return the tokens to the user or use them as needed.
These steps allow you to create a token for a user in Django using the rest_framework_simplejwt library.