jwt
Example
# settings.py
from dotenv import load_dotenv
import os
load_dotenv()
SECRET_KEY = os.environ.get('SECRET_KEY')
# Database
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': os.environ.get('DB_NAME'), #here
'USER': os.environ.get('DB_USER'), #here
'PASSWORD': os.environ.get('DB_PASS'), #here
'HOST': '127.0.0.1',
'PORT': '3306',
'OPTIONS': {'init_command': "SET sql_mode='STRICT_TRANS_TABLES'"},
}
}
# Add
REST_FRAMEWORK = {
'DEFAULT_AUTHENTICATION_CLASSES': [
'rest_framework_simplejwt.authentication.JWTAuthentication',
'rest_framework.authentication.SessionAuthentication',
],
}
Simple JWT
Simple JWT provides a JSON Web Token authentication backend for the Django REST Framework. A JSON Web Token authentication plugin for the Django REST Framework.
Tip
Project Configuration
Then, your django project must be configured to use the library. In settings.py
, add rest_framework_simplejwt.authentication.JWTAuthentication
to the list of authentication classes:
Tip
Also, in your root urls.py
file (or any other url config), include routes for Simple JWT’s TokenObtainPairView
and TokenRefreshView
views:
Tip