【发布时间】:2021-03-16 22:31:51
【问题描述】:
我有以下
REST_FRAMEWORK = {
'DEFAULT_PERMISSION_CLASSES': (
'rest_framework.permissions.AllowAny',
),
'DEFAULT_AUTHENTICATION_CLASSES': (
'rest_framework.authentication.TokenAuthentication',
),
'DEFAULT_RENDERER_CLASSES': (
'rest_framework.renderers.JSONRenderer',
'rest_framework.renderers.BrowsableAPIRenderer',
)
}
DRF 如何获得request.user
def hello_world(request):
print(request.user)
return Response()
我在努力
curl --location --request GET "http://127.0.0.1:8000/hello-world/" \
--header "Authorization:Token ssssss28acbd550a9806c6ac9ce13f1bbc73137" \
--header 'Content-Type: application/json'
所以在输出中我看到request.user 是根据提供的令牌打印的,例如:test
那使用isAuthenticated有什么用
它只检查是否提供了 Authentication 标头
为什么tokenauthentication 自己不能检查
【问题讨论】:
标签: django django-rest-framework