django create token for user

To create a token for a user in Django, you can follow these steps:

  1. Import the necessary modules and functions: python from rest_framework_simplejwt.tokens import RefreshToken

  2. Generate a token for the user: python token = RefreshToken.for_user(user)

  3. Access the access and refresh tokens: python access_token = str(token.access_token) refresh_token = str(token)

  4. 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.