【发布时间】:2021-09-30 07:43:42
【问题描述】:
class ProductViewSet(viewsets.ModelViewSet):
queryset = ProductInfo.objects.all().order_by('-id')
serializer_class = ProductSerializer
permission_classes = [IsAdminUser]
authentication_classes = []
filter_backends = (filters.SearchFilter,)
search_fields = ['title','code','owner__username']
大家好!我尝试使用 DRF 和邮递员获取我的产品列表...我尝试了几次,但我得到了一个错误,就像我说的那样。我的authentication_classes 是默认的TokenAuthentication,我有权限类..这个错误是为了我的权限
PLZ帮帮我。谢谢
我想我需要在这里做点什么。
【问题讨论】:
-
你能发布相关的DRF代码吗?
-
当然。我添加了...
-
你看到这篇文章了吗?看起来很相似。 stackoverflow.com/questions/58151021/…。看起来
TokenAuthenticationauthentication_class 是显式设置的,即使它是authentication_classes默认值。你可以试试看。 -
感谢您的回答,但现在我得到“详细信息”:“未提供身份验证凭据。”
-
嗯,我不知道,抱歉。我只能说确保在 Postman 中选择了“授权”,并确保令牌根据 Django rest 框架文档以正确的格式写入,即“令牌 0390a72cadc ....”。否则,据我所知,一切看起来都不错。
标签: django-rest-framework permissions postman