仅在 POST 中使用令牌,而不是在 GET http 请求中使用令牌 (Django DRF) +不缓存
我正在使用 Django (DRF) 进行身份验证,并且它正在工作。 但是,我想仅将令牌用于 POST 请求,而不是 GET 请求。 是否可以 ?
我的代码: 设置:
# REST API
"rest_framework",
"rest_framework.authtoken",
和:
REST_FRAMEWORK = {
"DEFAULT_PERMISSION_CLASSES": ("rest_framework.permissions.IsAuthenticated",),
"DEFAULT_AUTHENTICATION_CLASSES": (
# "rest_framework.authentication.BasicAuthentication",
# "rest_framework.authentication.SessionAuthentication",
"rest_framework.authentication.TokenAuthentication",
),
}
如果我添加或不添加这一行,都是一样的:
class BlaBlaViewSet(APIView):
#permission_classes = (IsAuthenticated,)
那么,我该如何在“post”功能而不是“put”功能中做到这一点?
还有,如何禁用缓存请求?
I'm using authentification with Django (DRF), and it's working.
But, I would like to use the Token only with POST request and not GET requests.
Is it possible ?
My code :
Settings :
# REST API
"rest_framework",
"rest_framework.authtoken",
and :
REST_FRAMEWORK = {
"DEFAULT_PERMISSION_CLASSES": ("rest_framework.permissions.IsAuthenticated",),
"DEFAULT_AUTHENTICATION_CLASSES": (
# "rest_framework.authentication.BasicAuthentication",
# "rest_framework.authentication.SessionAuthentication",
"rest_framework.authentication.TokenAuthentication",
),
}
If I add this line, or not, it's the same :
class BlaBlaViewSet(APIView):
#permission_classes = (IsAuthenticated,)
So, how can I do that in the "post" function and not in "put" function, please ?
And, how to disable caching requests please ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论