1.下载
pip install djangorestframework-jwt
2.在settings.py中配置
# 1、在INSTALLED_APPS中加入'rest_framework.authtoken'
'rest_framework.authtoken'
# # 2、配置jwt验证
REST_FRAMEWORK = {
# 身份认证
'DEFAULT_AUTHENTICATION_CLASSES': (
'rest_framework_jwt.authentication.JSONWebTokenAuthentication',
'rest_framework.authentication.SessionAuthentication',
'rest_framework.authentication.BasicAuthentication',
),
# 全局配置JWT验证设置
# 'DEFAULT_PERMISSION_CLASSES': (
# # 'rest_framework.permissions.IsAuthenticated',
# ),
}
import datetime
JWT_AUTH = {
'JWT_AUTH_HEADER_PREFIX': 'JWT',
'JWT_EXPIRATION_DELTA': datetime.timedelta(days=1),
'JWT_RESPONSE_PAYLOAD_HANDLER':
'users.views.jwt_response_payload_handler',