标签:work 后台 one auth cat return rom basic asi
REST_FRAMEWORK = {
# 全局配置 - 配置认证类
'DEFAULT_AUTHENTICATION_CLASSES': (
# 'rest_framework.authentication.SessionAuthentication',
# 'rest_framework.authentication.BasicAuthentication',
# 'api.authentication.TokenAuthentication',
)
}
# 自定义认证类
# 前后台分离项目,认证字段通常为Token
from rest_framework.authentication import BaseAuthentication
from rest_framework import exceptions
class TokenAuthentication(BaseAuthentication):
def authenticate(self, request):
token = request._request.META.get('HTTP_TOKEN')
if token != '123321':
raise exceptions.NotAuthenticated('认证失败')
return None
# 局部解除认证
authentication_classes = ()
from . import authentication
authentication_classes = (authentication.TokenAuthentication, )
app.表名
AUTH_USER_MODEL = 'api.User'
标签:work 后台 one auth cat return rom basic asi
原文地址:https://www.cnblogs.com/huanghongzheng/p/11380130.html