# pip install djangorestframework-simplejwt[crypto]
# setting.py
INSTALLED_APPS = [
...
'rest_framework_simplejwt',
...
]
REST_FRAMEWORK = {
...
'DEFAULT_AUTHENTICATION_CLASSES': (
...
'rest_framework_simplejwt.authentication.JWTAuthentication',
)
...
}
# View.py
#mefiz.com
from rest_framework_simplejwt.tokens import RefreshToken
def get_tokens_for_user(user):
refresh = RefreshToken.for_user(user)
return {
'refresh': str(refresh),
'access': str(refresh.access_token),
}
def home(request):
user = authenticate(username="admin", password="admin") # check for email and passwor
print(user)
tokens = get_tokens_for_user(user)
return JsonResponse(tokens)
# More Details https://django-rest-framework-simplejwt.readthedocs.io/en/latest/